Method 1: directly call
Copy codeThe Code is as follows:
<?
/*************************************** ***************************************/
/* File name: soapclient. php
/* Description: WebService interface client routine
/*************************************** ***************************************/
Include ('nusoap. php ');
// Create a soapclient object whose parameter is server's WSDL
$ Client = new soapclient ('HTTP: // localhost/Webservices/Service. asmx? WSDL ', 'wsdl ');
// Input parameters in array format
$ AryPara = array ('strusername' => 'username', 'strpassword' => MD5 ('Password '));
// Call a remote Function
$ 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 codeThe Code is as follows:
<?
/*************************************** ***************************************/
/* File name: soapclient. php
/* Description: WebService interface client routine
/*************************************** ***************************************/
Include ('nusoap. php ');
// Create a soapclient object whose parameter is server's WSDL
$ Client = new soapclient ('HTTP: // localhost/Webservices/Service. asmx? WSDL ', 'wsdl ');
// Input parameters in array format
$ AryPara = array ('strusername' => 'username', 'strpassword' => MD5 ('Password '));
// Call a remote Function
$ 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 2: proxy call
Copy codeThe Code is as follows:
<?
/*************************************** ***************************************/
/* File name: soapclient. php
/* Description: WebService interface client routine
/*************************************** ***************************************/
Require ('nusoap. php ');
// Create a soapclient object whose parameter is server's WSDL
$ Client = new soapclient ('HTTP: // localhost/Webservices/Service. asmx? WSDL ', 'wsdl ');
// Generate proxy class
$ Proxy = $ client-> getProxy ();
// Call a remote Function
$ 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 codeThe Code is as follows:
<?
/*************************************** ***************************************/
/* File name: soapclient. php
/* Description: WebService interface client routine
/*************************************** ***************************************/
Require ('nusoap. php ');
// Create a soapclient object whose parameter is server's WSDL
$ Client = new soapclient ('HTTP: // localhost/Webservices/Service. asmx? WSDL ', 'wsdl ');
// Generate proxy class
$ Proxy = $ client-> getProxy ();
// Call a remote Function
$ 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 call. NET WebService or J2EE WebService may have encountered Chinese garbled characters. The following describes the causes and solutions of this problem.
Reasons for garbled WebService calling by NuSoap:
Usually we do WebService development is used for UTF-8 encoding, then we need to set:
Copy codeThe Code is as follows:
$ Client-> soap_defencoding = 'utf-8 ';
$ Client-> soap_defencoding = 'utf-8 ';
At the same time, xml must be transmitted in the same encoding mode:
Copy codeThe Code is as follows:
$ Client-> xml_encoding = 'utf-8 ';
$ Client-> xml_encoding = 'utf-8 ';
At this point, everything is normal, but when we output the results, we find that the returned code is garbled.
Solution to WebService call garbled by NuSoap:
In fact, a friend who has enabled the debugging function will find that $ client-> response returns the correct result. Why $ result = $ client-> call ($ action, array ('parameters '=> $ param); is it garbled?
After studying the NuSoap code, we will find that when xml_encoding is set to UTF-8, NuSoap will detect the decode_utf8 setting. If it is true, it will execute the utf8_decode function in PHP, nuSoap is set to true by default. Therefore, we need to set:
Copy codeThe Code is 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 ';