SOAP Web Service Tutorials - Herong's Tutorial Examples - v5.13, by Herong Yang
Call WSDL Operation with SoapClient::__doRequest()
This section provides a tutorial example on how to call an operation defined in a WSDL document using the __doRequest(request,...) function.
Instead of using the RPC style, we can also call a Web service in XML style by using the SoapClient::__doRequest() function:
Here a good example of a client program, NumberConversionDoRequest.php, on how to call a Web service with the SoapClient::__doRequest() function. The NumberConversion Web service and its WSDL document are provided by dataaccess.com.
<?php # NumberConversionDoRequest.php # Copyright (c) 2007 HerongYang.com. All Rights Reserved. # $client = new SoapClient(null, array('uri'=>'', 'location'=>'')); $request = <<<EOT <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.dataaccess.com/webservicesserver/"> <SOAP-ENV:Body> <ns1:NumberToWords> <ns1:ubiNum>303</ns1:ubiNum> </ns1:NumberToWords> </SOAP-ENV:Body> </SOAP-ENV:Envelope> EOT; $url = "https://www.dataaccess.com/webservicesserver/numberconversion.wso"; $response = $client->__doRequest($request,$url,"",SOAP_1_1); echo("Request:\n"); var_dump($request); echo("Response:\n"); var_dump($response); ?>
When running it, I am getting:
herong> php NumberConversionDoRequest.php Request: string(318) "<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.dataaccess.com/webservicesserver/"> <SOAP-ENV:Body> <ns1:NumberToWords> <ns1:ubiNum>303</ns1:ubiNum> </ns1:NumberToWords> </SOAP-ENV:Body> </SOAP-ENV:Envelope>" Response: string(356) "<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <m:NumberToWordsResponse xmlns:m="http://www.dataaccess.com/webservicesserver/"> <m:NumberToWordsResult>three hundred and three </m:NumberToWordsResult> </m:NumberToWordsResponse> </soap:Body> </soap:Envelope>"
Good. Now I know how to call a Web service with SOAP request XML message directly without using the WSDL document.
Table of Contents
Introduction to SOAP (Simple Object Access Protocol)
SOAP Message Transmission and Processing
SOAP MEP (Message Exchange Patterns)
►PHP SOAP Extension Client Programs
PHP SOAP Extension Functions for Client Programs
Calling WSDL Operation Directly
Call WSDL Operation with SoapClient::__soapCall()
Dumping SOAP Request and Response
►Call WSDL Operation with SoapClient::__doRequest()
PHP SOAP Extension Server Programs
PHP SOAP Web Service Example - getTemp
Perl SOAP::Lite - SOAP Server-Client Communication Module
Perl Socket Test Program for HTTP and SOAP
Perl SOAP::Lite for NumberToWords SOAP 1.1 Web Service
Perl SOAP::Lite for SOAP 1.2 Web Services
Java Socket and HttpURLConnection for SOAP
SAAJ - SOAP with Attachments API for Java
SoapUI - SOAP Web Service Testing Tool
WS-Security - SOAP Message Security Extension
WS-Security X.509 Certificate Token
Perl SOAP::Lite for GetSpeech SOAP 1.1 Web Service
Perl SOAP::Lite 0.710 for SOAP 1.2 Web Services
Perl SOAP::Lite 0.710 for WSDL