Method One: Direct call
The code is as follows |
Copy Code |
?
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;
$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
The code is as follows |
Copy Code |
?
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;
$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;
?> |
Nusoap Call WebService the reason for garbled:
Usually we use the UTF-8 code for WebService development, when we need to set:
The code is as follows |
Copy Code |
$client->soap_defencoding = ' utf-8′; |
At the same time, XML needs to be passed in the same encoding:
The code is as follows |
Copy Code |
$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, the friend that turned on the debugging function, I believe will find $client->response return is the correct result, why
The code is as follows |
Copy Code |
$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:
PHP Code
code is as follows |
copy code |
$client-> soap_defencoding = ' utf-8′; $client->decode_utf8 = false; $client- >xml_encoding = ' utf-8′; |