Use PHP to invoke the webservice developed by the Java language.
The client submits two arguments of type string, and the server returns an object type.
The server uses AXIS-1.4 as the SOAP engine. The client is PHP5.2.9 and uses nusoap as the SOAP engine.
Service side
Object class
Copy the Code code as follows:
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.) {
This.age = age;
}
public Boolean getsex () {
return sex;
}
public void Setsex (Boolean sex) {
This.sex = sex;
}
}
Service class
Copy the Code code as follows:
public class Userlogin {
Public person Login (string loginName, String loginpasswd) {
Person Aperson = new person ();
if (Loginname.equals ("Laoli") && loginpasswd.equals ("111111")) {
Aperson.setusername ("Lao Li");
Aperson.setage (55);
Aperson.setsex (TRUE);
} else if (Loginname.equals ("Xiaoli") && loginpasswd.equals ("123456")) {
Aperson.setusername ("Xiao Li");
Aperson.setage (23);
Aperson.setsex (FALSE);
} else {
Aperson = null;
}
return Aperson;
}
}
Client
Copy the Code code as follows:
/*
* 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 '
Constructor Error
' . $err. '
';
At this point, you know the follows would fail
}
Call the SOAP method
$param =array (' loginName ' = ' laoli ', ' loginpasswd ' = ' 111111 ');
$result = $client->call (' login ', $param);
Check for a fault
if ($client->fault) {
Echo '
Fault
';
Print_r ($result);
Echo '
';
} else {
Check for errors
$err = $client->geterror ();
if ($err) {
Display the error
Echo '
Error
' . $err. '
';
} else {
Display the result
Echo '
Result
';
Print_r ($result);
Echo '
';
}
}
Echo '
';
$param =array (' loginName ' = ' Xiaoli ', ' loginpasswd ' = ' 123456 ');
$result = $client->call (' login ', $param);
Check for a fault
if ($client->fault) {
Echo '
Fault
';
Print_r ($result);
Echo '
';
} else {
Check for errors
$err = $client->geterror ();
if ($err) {
Display the error
Echo '
Error
' . $err. '
';
} else {
Display the result
Echo '
Result
';
Print_r ($result);
Echo '
';
}
}
?>
http://www.bkjia.com/PHPjc/740216.html www.bkjia.com true http://www.bkjia.com/PHPjc/740216.html techarticle use PHP to invoke the webservice developed by the Java language. The client submits two arguments of type string, and the server returns an object type. The server uses AXIS-1.4 as the SOAP engine. The client is ...