Use PHP to invoke the Java language development webservice.
The client submits two string parameters, and the service side returns an object type.
The service side uses AXIS-1.4 as the SOAP engine. The client is PHP5.2.9, using Nusoap as the SOAP engine.
Service side
Object class
Copy 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 age) {
This.age = age;
}
public Boolean getsex () {
return sex;
}
public void Setsex (Boolean sex) {
This.sex = sex;
}
}
Service class
Copy 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 ("Xiaoli");
Aperson.setage (23);
Aperson.setsex (FALSE);
} else {
Aperson = null;
}
return Aperson;
}
}
Client
Copy Code code as follows:
<?php
/*
* 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 ' At this point, your know the call that 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 ' Print_r ($result);
Echo ' </pre> ';
} else {
Check for errors
$err = $client->geterror ();
if ($err) {
Display the error
Echo ' } else {
Display the result
Echo ' 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 ' Print_r ($result);
Echo ' </pre> ';
} else {
Check for errors
$err = $client->geterror ();
if ($err) {
Display the error
Echo ' } else {
Display the result
Echo ' Print_r ($result);
Echo ' </pre> ';
}
}
?>