SOAP Web Service Tutorials - Herong's Tutorial Examples - v5.13, by Herong Yang
soapversion('1.2') and envprefix('soap12') Must Used Together
This section provides a tutorial example on how to set the Envelope element under a named namespace of 'http://www.w3.org/2003/05/soap-envelope' - Using soapversion('1.2') and envprefix('soap12') together!
The first issue is to set the Envelope element under a named namespace of "http://www.w3.org/2003/05/soap-envelope". I did 3 tests before finding the solution:
1. Using soapversion('1.1') only.
#- NumberToWords_localhost_v11.pl #- Copyright (c) 2009 HerongYang.com. All Rights Reserved. # use SOAP::Lite +trace; my $client = SOAP::Lite->new() ->soapversion('1.1') ->readable(true) ->proxy('http://localhost/NumberConversion.wso'); my $som = $client->call('NumberToWords', 102);
Result of NumberToWords_localhost_v11.pl:
POST http://localhost/NumberConversion.wso HTTP/1.1 Accept: text/xml Accept: multipart/* Accept: application/soap Content-Length: 494 Content-Type: text/xml; charset=utf-8 SOAPAction: "#NumberToWords" <?xml version="1.0" encoding="UTF-8"?> <soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <NumberToWords> <c-gensym3 xsi:type="xsd:int">102</c-gensym3> </NumberToWords> </soap:Body> </soap:Envelope>
2. Using soapversion('1.2') only.
#- NumberToWords_localhost_v12.pl #- Copyright (c) 2009 HerongYang.com. All Rights Reserved. # use SOAP::Lite +trace; my $client = SOAP::Lite->new() ->soapversion('1.2') ->readable(true) ->proxy('http://localhost/NumberConversion.wso'); my $som = $client->call('NumberToWords', 102);
Result of NumberToWords_localhost_v12.pl:
POST http://localhost/NumberConversion.wso HTTP/1.1 Accept: text/xml Accept: multipart/* Accept: application/soap Content-Length: 474 Content-Type: application/soap+xml; charset=utf-8 SOAPAction: "#NumberToWords" <?xml version="1.0" encoding="UTF-8"?> <Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Body> <NumberToWords> <c-gensym3 xsi:type="xsd:int">102</c-gensym3> </NumberToWords> </Body> </Envelope>
3. Using soapversion('1.2') and envprefix('soap12').
#- NumberToWords_localhost_v12_envprevix.pl #- Copyright (c) 2009 HerongYang.com. All Rights Reserved. # use SOAP::Lite +trace; my $client = SOAP::Lite->new() ->soapversion('1.2') ->envprefix('soap12') ->readable(true) ->proxy('http://localhost/NumberConversion.wso'); my $som = $client->call('NumberToWords', 102);
Result of NumberToWords_localhost_v12_envprevix.pl:
POST http://localhost/NumberConversion.wso HTTP/1.1 Accept: text/xml Accept: multipart/* Accept: application/soap Content-Length: 562 Content-Type: application/soap+xml; charset=utf-8 SOAPAction: "#NumberToWords" <?xml version="1.0" encoding="UTF-8"?> <soap12:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap12:Body> <NumberToWords> <c-gensym3 xsi:type="xsd:int">102</c-gensym3> </NumberToWords> </soap12:Body> </soap12:Envelope>
What is your conclusion based on these tests? Here is what I think:
So if you want to do SOAP 1.2, remember to use soapversion('1.2') and envprefix('soap12') together!
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 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
Message Styles Supported in SOAP::Lite
Methods on SOAP::Lite Client Object
Testing SOAP::Lite Client Objects
Differences between SOAP 1.1 and SOAP 1.2
NumberToWords_localhost.pl - Testing on Local Host
►soapversion('1.2') and envprefix('soap12') Must Used Together
default_ns() - Setting Namespace for Body Elements
SOAP::Data - Utility Class to Generate XML Elements
SOAPAction - Not Needed, But No Way to Remove It
NumberToWords_SOAP_1_2.pl - SOAP::Lite for SOAP 1.2 Web Service
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