PHP调用JAVA的WebService的解决办法
内容摘要
这篇文章主要为大家详细介绍了PHP调用JAVA的WebService的简单示例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随php教程的小玲来看看吧!
使用PHP调用JA
感兴趣的小伙伴,下面一起跟随php教程的小玲来看看吧!
使用PHP调用JA
文章正文
这篇文章主要为大家详细介绍了PHP调用JAVA的WebService的简单示例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随php教程的小玲来看看吧!
使用PHP调用JAVA语言开发的WebService。客户端提交两个String类型的参数,服务端返回一个对象类型。服务端使用AXIS-1.4作为SOAP引擎。客户端为PHP5.2.9,使用NuSOAP作为SOAP引擎。
服务端
对象类
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <code>import java.io.Serializable; public class Person implements Serializable { /** * */ private static final long serialVersionUID = -410186774891162281L; private String username; private int age; private boolean sex; // true:male;false:female public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public boolean getSex() { return sex; } public void setSex(boolean sex) { this.sex = sex; } }</code> |
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <code> public class UserLogin { public Person login(String loginName, String loginPasswd) { Person aPerson = new Person(); if (loginName.equals( "laoli" ) && loginPasswd.equals( "111111" )) { aPerson.setUsername( "老李" ); aPerson.setAge(55); aPerson.setSex(true); } else if (loginName.equals( "xiaoli" ) && loginPasswd.equals( "123456" )) { aPerson.setUsername( "小丽" ); aPerson.setAge(23); aPerson.setSex(false); } else { aPerson = null; } return aPerson; } }</code> |
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | <code><?php /* php教程 www.512Pic.com */ /* * Created on 2011-10-12 * Author wanghao * * package_name/userLoginClient.php */ header( "Content-Type: text/html;charset=utf-8" ); // Pull in the NuSOAP code require_once ( "libs/nusoap.php" ); // Create the client instance $client = new nusoapclient( 'http://localhost:8080/axis/services/UserLoginWS?wsdl' , true); $client ->soap_defencoding = 'utf-8' ; $client ->decode_utf8 = false; $client ->xml_encoding = 'utf-8' ; // Check for an error $err = $client ->getError(); if ( $err ) { // Display the error echo '<h2>Constructor error</h2><pre>' . $err . '</pre>' ; // At this point, you know the call that follows will fail } // Call the SOAP method $param = array ( 'loginName' => 'laoli' , 'loginPasswd' => '111111' ); $result = $client ->call( 'login' , $param ); // Check for a fault if ( $client ->fault) { echo '<h2>Fault</h2><pre>' ; print_r( $result ); echo '</pre>' ; } else { // Check for errors $err = $client ->getError(); if ( $err ) { // Display the error echo '<h2>Error</h2><pre>' . $err . '</pre>' ; } else { // Display the result echo '<h2>Result</h2><pre>' ; print_r( $result ); echo '</pre>' ; } } echo '<br>' ; $param = array ( 'loginName' => 'xiaoli' , 'loginPasswd' => '123456' ); $result = $client ->call( 'login' , $param ); // Check for a fault if ( $client ->fault) { echo '<h2>Fault</h2><pre>' ; print_r( $result ); echo '</pre>' ; } else { // Check for errors $err = $client ->getError(); if ( $err ) { // Display the error echo '<h2>Error</h2><pre>' . $err . '</pre>' ; } else { // Display the result echo '<h2>Result</h2><pre>' ; print_r( $result ); echo '</pre>' ; } } ?></code> |
注:关于PHP调用JAVA的WebService的简单示例的内容就先介绍到这里,更多相关文章的可以留意
代码注释