Method One: Direct call
Copy Code code as follows:
?
/******************************************************************************/
/* FileName: soapclient.php
/* Description: WebService interface Client Routines
/******************************************************************************/
Include (' nusoap.php ');
Creates a SoapClient object, which is the WSDL of the server
$client = new SoapClient (' Http://localhost/Webservices/Service.asmx?WSDL ', ' WSDL ');
parameter to the array form
$aryPara = Array (' strUserName ' => ' username ', ' strpassword ' =>md5 (' password '));
Calling remote functions
$aryResult = $client->call (' login ', $aryPara);
Echo $client->debug_str;
/*
if (! $err = $client->geterror ()) {
Print_r ($aryResult);
} else {
Print "ERROR: $err";
}
*/
$document = $client->document;
Echo <<<soapdocument
<?xml version= "1.0" encoding= "GB2312"?>
<soap-env:envelope soap-env:encodingstyle= "http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap-env= "http:// schemas.xmlsoap.org/soap/envelope/"xmlns:xsd=" Http://www.w3.org/2001/XMLSchema "xmlns:xsi=" http://www.w3.org/ 2001/xmlschema-instance "xmlns:soap-enc=" http://schemas.xmlsoap.org/soap/encoding/"xmlns:si=" http:// Soapinterop.org/xsd ">
<SOAP-ENV:Body>
$document
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Soapdocument;
?>
Copy Code code as follows:
?
/******************************************************************************/
/* FileName: soapclient.php
/* Description: WebService interface Client Routines
/******************************************************************************/
Include (' nusoap.php ');
Creates a SoapClient object, which is the WSDL of the server
$client = new SoapClient (' Http://localhost/Webservices/Service.asmx?WSDL ', ' WSDL ');
parameter to the array form
$aryPara = Array (' strUserName ' => ' username ', ' strpassword ' =>md5 (' password '));
Calling remote functions
$aryResult = $client->call (' login ', $aryPara);
Echo $client->debug_str;
/*
if (! $err = $client->geterror ()) {
Print_r ($aryResult);
} else {
Print "ERROR: $err";
}
*/
$document = $client->document;
Echo <<<soapdocument
<?xml version= "1.0" encoding= "GB2312"?>
<soap-env:envelope soap-env:encodingstyle= "http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap-env= "http:// schemas.xmlsoap.org/soap/envelope/"xmlns:xsd=" Http://www.w3.org/2001/XMLSchema "xmlns:xsi=" http://www.w3.org/ 2001/xmlschema-instance "xmlns:soap-enc=" http://schemas.xmlsoap.org/soap/encoding/"xmlns:si=" http:// Soapinterop.org/xsd ">
<SOAP-ENV:Body>
$document
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Soapdocument;
?>
Method Two: Proxy method call
Copy Code code as follows:
?
/******************************************************************************/
/* FileName: soapclient.php
/* Description: WebService interface Client Routines
/******************************************************************************/
Require (' nusoap.php ');
Creates a SoapClient object, which is the WSDL of the server
$client =new soapclient (' Http://localhost/Webservices/Service.asmx?WSDL ', ' WSDL ');
Generate proxy class
$proxy = $client->getproxy ();
Calling remote functions
$aryResult = $proxy->login (' username ', MD5 (' password '));
Echo $client->debug_str;
/*
if (! $err = $proxy->geterror ()) {
Print_r ($aryResult);
} else {
Print "ERROR: $err";
}
*/
$document = $proxy->document;
Echo <<<soapdocument
<?xml version= "1.0" encoding= "GB2312"?>
<soap-env:envelope soap-env:encodingstyle= "http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap-env= "http:// schemas.xmlsoap.org/soap/envelope/"xmlns:xsd=" Http://www.w3.org/2001/XMLSchema "xmlns:xsi=" http://www.w3.org/ 2001/xmlschema-instance "xmlns:soap-enc=" http://schemas.xmlsoap.org/soap/encoding/"xmlns:si=" http:// Soapinterop.org/xsd ">
<SOAP-ENV:Body>
$document
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Soapdocument;
?>
Copy Code code as follows:
?
/******************************************************************************/
/* FileName: soapclient.php
/* Description: WebService interface Client Routines
/******************************************************************************/
Require (' nusoap.php ');
Creates a SoapClient object, which is the WSDL of the server
$client =new soapclient (' Http://localhost/Webservices/Service.asmx?WSDL ', ' WSDL ');
Generate proxy class
$proxy = $client->getproxy ();
Calling remote functions
$aryResult = $proxy->login (' username ', MD5 (' password '));
Echo $client->debug_str;
/*
if (! $err = $proxy->geterror ()) {
Print_r ($aryResult);
} else {
Print "ERROR: $err";
}
*/
$document = $proxy->document;
Echo <<<soapdocument
<?xml version= "1.0" encoding= "GB2312"?>
<soap-env:envelope soap-env:encodingstyle= "http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap-env= "http:// schemas.xmlsoap.org/soap/envelope/"xmlns:xsd=" Http://www.w3.org/2001/XMLSchema "xmlns:xsi=" http://www.w3.org/ 2001/xmlschema-instance "xmlns:soap-enc=" http://schemas.xmlsoap.org/soap/encoding/"xmlns:si=" http:// Soapinterop.org/xsd ">
<SOAP-ENV:Body>
$document
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Soapdocument;
?>
Many friends who use Nusoap to invoke. NET WebService or Java EE WebService may have encountered Chinese garbled problems, the following describes the causes of the problem and the corresponding solutions.
Nusoap Call WebService the reason for garbled:
Usually we use the UTF-8 code for WebService development, when we need to set:
Copy Code code as follows:
$client->soap_defencoding = ' utf-8 ';
$client->soap_defencoding = ' utf-8 ';
At the same time, XML needs to be passed in the same encoding:
Copy Code code as follows:
$client->xml_encoding = ' utf-8 ';
$client->xml_encoding = ' utf-8 ';
At this point should be all normal, but we are in the output of the results, but found that the return of garbled.
Nusoap Call WebService a garbled solution:
In fact, a friend who has turned on the debugging feature will find that $client->response is returning the correct result, why $result = $client->call ($action, Array (' Parameters ' => $ param)); But it's garbled?
After studying the NUSOAP code, we find that when xml_encoding is set to UTF-8, Nusoap detects Decode_utf8 settings, and if true, executes the Utf8_decode function in PHP, and Nusoap defaults to True , so we need to set:
Copy Code code as follows:
$client->soap_defencoding = ' utf-8 ';
$client->decode_utf8 = false;
$client->xml_encoding = ' utf-8 ';
$client->soap_defencoding = ' utf-8 ';
$client->decode_utf8 = false;
$client->xml_encoding = ' utf-8 ';