Herong's Tutorial Notes on Web Service and SOAP
Dr. Herong Yang, Version 4.00

soapversion('1.2') Sets Correct Envelope namespace

This section provides a tutorial example on how to use soapversion('1.2') to tell service() to use the correct namespace for the Envelope.

From previous tutorial, I learned that the service() function uses SOAP 1.1 by default and it put the wrong namespace to the Envelope. Now let me force it to use SOAP 1.2 and see what happens:

#- GetSpeech_WSDL_localhost_1_2.pl
#- Copyright (c) 2009 by Dr. Herong Yang, herongyang.com
#- All rights reserved
#
   use SOAP::Lite +trace;
   my $client = SOAP::Lite->new()
      ->soapversion('1.2')
      ->service('file:///C:/herong/GetSpeech.wsdl')
      ->readable('true');
      
#- Overriding the constant for SOAP 1.2
   $SOAP::Constants::DEFAULT_HTTP_CONTENT_TYPE 
      = 'application/soap+xml';

   $client->GetSpeech('To be, or not to be');

Result of GetSpeech_WSDL_localhost_1_2.pl:

POST http://localhost/soap11 HTTP/1.1
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Content-Length: 831
Content-Type: application/soap+xml; charset=utf-8
SOAPAction: "http://xmlme.com/WebServices/GetSpeech"

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
    xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
    xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
    soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding"
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
    xmlns:s="http://www.w3.org/2001/XMLSchema"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
    xmlns:tns="http://xmlme.com/WebServices">
  <soap:Body>
    <tns:GetSpeech>
      <Request xsi:type="s:string">To be, or not to be</Request>
    </tns:GetSpeech>
  </soap:Body>
</soap:Envelope>
...
500 Can't connect to localhost:80 (connect: Unknown error)

Note that:

  • soapversion('1.2') changed the Envelope namespace to the correct one: xmlns:soap="http://www.w3.org/2003/05/soap-envelope".
  • But the service() function still picked up the "port" defined for SOAP 1.1, because it uses "POST http://localhost/soap11 HTTP/1.1".

The request looks good to me now. I will try it with the real Web service server at xmlme.com in the next tutorial.

Last update: 2009.

Sections in This Chapter

First WSDL Test Failed with SOAP::Lite

Downloading and Editing WSDL Document

Testing service() Function Locally

soapversion('1.2') Sets Correct Envelope namespace

Error: Object reference not set to an instance of an object

Dr. Herong Yang, updated in 2009
soapversion('1.2') Sets Correct Envelope namespace