PHP processing WSDL

Source: Internet
Author: User
Tags wsdl

0x00 Preface

Recently the interface has been written, before which the interface data transfer is transmitted or obtained using JSON or XML format. But this time with third-party intermodulation, they were given the WSDL format. Instant seconds Change SB ...

Google to test with code, Test call third-party interface return status 200. I thought there was nothing to it. It's time to close, and then find out that no matter how they call them the interface is not the correct data echo. Then they looked over the log and found that the parameters they passed were not received, and the problem was solved by the afternoon until evening. I think it's interesting, so write it down first.

What is the 0x01 WSDL

To a certain degree, it is an XML-formatted document that describes the definition of Web server, that is, a Web server method and a parameter description.

See: Http://

When we ask for ', similar to the end of the WSDL URL, a lump of XML structure data is given to you.

Yes, just a lump of ...

Next, how to understand it and what it means is the key, the others are useless.

0x02 Understanding the Description document

It's a bit confusing to start looking at this XML document, but it's a lot more obvious with PHP extensions.

  __getfunctions ());p rint "related data structure \ n";p rint_r ($client->__gettypes ());p rint "\ n";

Here we use the SOAP extension, which is the PHP official copy to present the operation processing Webserver service extension, and finally we also through it to implement the parameter transmission.

As can be understood in the above image, this interface provides three methods, namely:




The relevant data organization refers to the parameter name in the method, and the parameter type. For example, a Xxxxuserinfo method requires three arguments of type string. corresponding to In0,in1 and in2 respectively.


The argument key here must be in0, which is an arbitrary parameter name without an array, user-defined, or mutually agreed upon. At the beginning of the writing interface method, I was based on the parameters given in the interface copy such as: err_msg (for error message), Err_code (indicating the error code), date (the final data transmitted) to transmit. After changing to an ordered array, fill in the corresponding parameters, at this time key is 0 to 2. Can try after or there is no egg, finally wrapped in a try to try the mentality, try to int0 as the key name, the corresponding err_msg content as a value. ok~, perfect solution.


  ' false ', ' err_code ' = ' 0 ', ' date ' = ' Here is the data to be transferred '];        Public Function SetUp () {$client = new soapclient (' ');        Print "supplied method \ n";        Print_r ($client->__getfunctions ());        Print "Related data structure \ n";        Print_r ($client->__gettypes ());    print "\ n"; }/** * Xxxxuserinfo method */Public Function Testxxxxuserinfodata () {try {$ApiInfo = $th            is->infoarr; Set request param $parameter = array (' in0 ' = = $ApiInfo [' err_msg '], ' in1 ' =& Gt            $ApiInfo [' Err_code '], ' in2 ' = ' $ApiInfo [' Date '];            $result = $this->getsoapclienthandler ()->synchuserinfo ($parameter); The call result returns an exception if (! $result instanceof StdClass) {throw new Exception ("Call Synchuserinfo result exception:".            Json_encode ($result));         }//Call interface status code, output corresponding error details   if ($result->out = = ' ") {throw new Exception (" Call Synchuserinfo=>error: ". $result->out.            ", msg: Interface Data Exception");            } $xml _parser = Xml_parser_create ();                if (!xml_parse ($xml _parser, $result->out, True)) {Xml_parser_free ($xml _parser);            throw new Exception ("Call Synchuserinfo returns not an XML struct");            } xml_parser_free ($xml _parser);            XXE Libxml_disable_entity_loader (TRUE);            $xml = simplexml_load_string ($result->out, ' simplexmlelement ', libxml_nocdata);            Output parameter Var_dump ($xml->data); echo "Success".        Php_eol; } catch (SoapFault $soapFault) {throw new Exception ($soapFault->getmessage (). $this->getsoapclienthandl        ER ()->__getlastresponse ()); }}/** * @description Getsoapclienthandler */Public Function Getsoapclienthandler () {if (!se LF:: $soapClientHandler) {self:: $soapClientHandler = new SoapClient ($this->getsynchapi ());    } return Self:: $soapClientHandler;    }/** * @description GETSYNCHAPI */Public Function Getsynchapi () {return $this->apiurl; }}?>
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.