A detailed explanation of the WEBSERVICE class linked to PHP. PHP link WEBSERVICE code instance: communication class starts classwebserv {webservice address parameter var $ webaddarray (publclient. asmx? Wsdl, clientClient. asmx? Wsdl, bann); call
PHP links to a web service code instance:
- // Start the communication class
- Class webserv
- {
- // Webservice address parameters
- Var $ webadd = array (
- "Publ" =>"Client. asmx? Wsdl ",
- "Client" =>"Client. asmx? Wsdl ",
- "Bann" =>"");
- // Call webservice
- Function soap ($ class, $ function, $ par = array ()){
- // Link
- Web service
- $ Client = new SoapClient ($ this->Webadd [$ class]);
- $ Require = $ client->$ Function ($ par );
- // Call information debug
- If (is_soap_fault ($ require )){
- Echo "remote interface". $ function. "failed to call! ";
- Exit ();
- }
- // Obtain the returned value
- $ Function_result = $ function. "Result ";
- $ Str = $ require->$ Function_result;
- // Parse XML
- $ Row = @ simplexml_load_string ($ str );
- // If XML parsing is not supported, return directly
- If ($ row = false ){
- If (is_string ($ str )){
- Return $ str;
- } Else {
- $ Require = (get_object_vars ($ str ));
- $ Str = $ require ['string'];
- Return $ str;
- }
- }
- // Convert the result to an array
- $ Row_arr = get_object_vars ($ row );
- Print_r ($ row_arr); exit ();
- $ Row_return = $ row_arr ['table'];
- // Determine whether multiple feedback records exist.
- If (is_array ($ row_arr ['table']) {
- Foreach ($ row_return as $ key =>$ Vlaues ){
- $ Rows [$ key] = get_object_vars ($ vlaues );
- }
- } Else {
- $ Rows [0] = get_object_vars ($ row_arr ['table']);
- }
- // Communication record
- // $ This->Soap_log ($ class, $ function, $ par, $ rows );
- Return $ rows;
- }
- // Interface communication record
- Function soap_log ($ class, $ function, $ in, $ out ){
- $ Log = date ("Y-m-d H: I: s ");
- $ Log. = "". $ class ."->". $ Function." input :";
- $ Input = "";
- If ($ in! = Array ()){
- Foreach ($ in as $ key =>$ Vlaue ){
- $ Input. = $ key. "=". $ vlaue;
- }
- $ Log. = $ input. "output:". var_export ($ rows). "n ";
- }
- }
- }
The above is the communication content. Easy to use
Include PHP links to web service files
- <?
- Include "./webserv. class. php ";
- $ Webserv = new webserv;
- // Here is the parameter passed by the call method.
- $ A = array ("aa" => "aaaa ");
- Print_r ($ webser-> soap ("function_name", $ ));
- ?>
The above describes how to use PHP to link the web service class.
Consumer SERVICE Code instance: // The communication class starts classwebserv {// webservice address parameter var $ webadd = array (publ = client. asmx? Wsdl, client = Client. asmx? Wsdl, bann =); // call...