Let's talk about how PHP calls Webservice and its source code. Method 1: directly call and copy the code as follows :? **************************************** * ************************************ File name: soapclient. php * Description: We Method 1: Direct call
The 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 <
$ Document
SoapDocument;
?>
The 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 <
$ Document
SoapDocument;
?>
Method 2: proxy call
The 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 <
$ Document
SoapDocument;
?>
The 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 <
$ Document
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:
The 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:
The 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:
The 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 ';
The pipeline code is as follows :? /*************************************** ***************************************/ /* File name: soapclient. php/* Description: We...