简体   繁体   中英

PHP - Connecting with webservice API using SOAP WSDL

One of my customers recently asked me to integrate his webservice with some external companies API. I have to add integration controller in PHP as this is how his form is being processed.

The company provided me with:

1) WSDL definition of web service,

2) An example named contract.xml,

3) Two .xsd files that are to be used to data validation,

4) Three .xml examples (of soap request, response-true and response-false)

I've never done anything like this and i'm wondering if there's any point trying, would be very grateful if anyone could provide me with some knowledge that would let me start thinking my own way on this subject.

What would be the schema like: setting 'blank' request as PHP var and updating it with forms input would be good solution? Or should i rather try to learn some more on XML parsing and go this way?

you don't need to parse any xml, if you have WSDL (web service documentation language) xml file or you have online access to the wsdl of the service with which you going to comunicate, all that you should do define the object

$mySoapClient = new SoapClient("path/to/your/wsdl.xml", array("here you should write the params that required your soap service"));

also there might be user credential which you can set with

$soapClient = new SoapClient("https://soapserver.example.com/blahblah.asmx?wsdl"); 

// Prepare SoapHeader parameters 
$sh_param = array( 
            'Username'    =>    'username', 
            'Password'    =>    'password'); 
$headers = new SoapHeader('http://soapserver.example.com/webservices', 'UserCredentials', $sh_param); 

// Prepare Soap Client 
$soapClient->__setSoapHeaders(array($headers)); 

after connection you will use your $soapClient object to get access to all methods that provide your soap server like this

$soapClient->someMethodThatProvideMySoapServer($someParams);

this method someMethodThatProvideMySoapServer you don't have in your server this coming from soap server and you can use it for more detailes you can learn from here http://php.net/manual/en/book.soap.php http://php.net/manual/en/class.soapclient.php Creating a SOAP call using PHP with an XML body

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM