If you go to SOAP services, I highly recommend that you learn the basics once and then use this great tool again and again. There are many features that you can use, or you will reinvent the wheel and struggle with creating xml files, analyzing xml files, crashes, etc. Use prepared tools, and your life will be easier, and your code is better (fewer errors).
See http://www.php.net/manual/en/soapclient.soapcall.php#example-5266 how to use the SOAP web service. This is not so hard to understand.
Here is some code how you can analyze webserivce. Then create map types for classes and just send and receive php objects. You can find some tool for creating classes automatically ( http://www.urdalen.no/wsdl2php/manual.php ).
<?php try { $client = new SoapClient('http://b2b.freightquote.com/WebService/QuoteService.asmx?WSDL'); // read function list $funcstions = $client->__getFunctions(); var_dump($funcstions); // read some request obejct $response = $client->__getTypes(); var_dump($response); } catch (SoapFault $e) { // do some service level error stuff } catch (Exception $e) { // do some application level error stuff }
If you use the wsdl2php generation tool, everything will be very simple:
<?php require_once('./QuoteService.php'); try { $client = new QuoteService(); // create request $tracking = new TrackingRequest(); $tracking->BOLNumber = 67635735; $request = new GetTrackingInformation(); $request->request = $tracking; // send request $response = $client->GetTrackingInformation($request); var_dump($response); } catch (SoapFault $e) { // do some service level error stuff echo 'Soap fault ' . $e->getMessage(); } catch (Exception $e) { // do some application level error stuff echo 'Error ' . $e->getMessage(); }
You can see the generated PHP code for QuoteService.php here: http://pastie.org/8165331
This is a captured message:
Request
POST /WebService/QuoteService.asmx HTTP/1.1 Host: b2b.freightquote.com Connection: Keep-Alive User-Agent: PHP-SOAP/5.4.17 Content-Type: text/xml; charset=utf-8 SOAPAction: "http://tempuri.org/GetTrackingInformation" Content-Length: 324 <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/"> <SOAP-ENV:Body> <ns1:GetTrackingInformation> <ns1:request> <ns1:BOLNumber>67635735</ns1:BOLNumber> </ns1:request> </ns1:GetTrackingInformation> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Answer
HTTP/1.1 200 OK Date: Mon, 22 Jul 2013 21:46:06 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private, max-age=0 Content-Type: text/xml; charset=utf-8 Content-Length: 660 Set-Cookie: BIGipServerb2b_freightquote_com=570501130.20480.0000; path=/ <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <GetTrackingInformationResponse xmlns="http://tempuri.org/"> <GetTrackingInformationResult> <BOLNumber>0</BOLNumber> <EstimatedDelivery>0001-01-01T00:00:00</EstimatedDelivery> <TrackingLogs /> <ValidationErrors> <B2BError> <ErrorType>Validation</ErrorType> <ErrorMessage>Unable to find shipment with BOL 67635735.</ErrorMessage> </B2BError> </ValidationErrors> </GetTrackingInformationResult> </GetTrackingInformationResponse> </soap:Body> </soap:Envelope>