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

GetSpeech_SOAP_1_2.pl - SOAP::Lite for SOAP 1.2 Web Service

This section provides a tutorial example on how to use SOAP::Lite 0.710 to call a SOAP 1.2 Web service, GetSpeech, provided by a .NET server at xmlme.com

Enough hacking on the SOAP::Lite code, it's time to finalize my GetSpeech SOAP 1.2 client program. I decided to set DEFAULT_HTTP_CONTENT_TYPE constant to fix the media type issue.

#- GetSpeech_SOAP_1_2.pl
#- Copyright (c) 2009 by Dr. Herong Yang, herongyang.com
#- All rights reserved
#
   use SOAP::Lite;

   my $proxy = 'http://www.xmlme.com/WSShakespeare.asmx';
   my $uri = 'http://xmlme.com/WebServices';
   my $method = "GetSpeech";
   my $soapAction = sub {return "$uri/$method"};
   
   my ($phrase) = @ARGV;

#- Building the parameter element
   my $parameter = SOAP::Data
        ->name("Request") # set the element name
        ->value($phrase); # set the value

#- Creating the SOAP client object
   my $client = SOAP::Lite->new()
      ->soapversion('1.2') # set to SOAP 1.2
      ->envprefix('soap12') # set prefix for SOAP 1.2 namespace
      ->default_ns($uri) # set the default namespace for method
      ->on_action($soapAction) # set the SOAPAction
      ->readable(true) # make the XML readable
      ->proxy($proxy); # set the proxy URL
      
#- Overriding the constant
   $SOAP::Constants::DEFAULT_HTTP_CONTENT_TYPE 
      = 'application/soap+xml';

#- Calling the Web service
   my $som = $client->call($method=>($parameter));
   my $output = $som->result;
   print $output . "\n";

When executing GetSpeech_SOAP_1_2.pl, I got this:

\herong>GetSpeech_SOAP_1_1.pl "To be, or not to be"
<SPEECH><PLAY>HAMLET</PLAY><SPEAKER>HAMLET</SPEAKER>
To be, or not to be: that is the question: Whether 'tis nobler 
in the mind to suffer The slings and arrows of outrageous fortune, 
...</SPEECH>

The result is identical to GetSpeech_SOAP_1_1.pl developed previously.

Last update: 2009.

Sections in This Chapter

Installing SOAP::Lite 0.710 to Support SOAP 1.2

Features in SOAP::Lite 0.710

Methods on SOAP::Lite 0.710 Client Object

Testing SOAP::Lite Client Objects

Request Differences between SOAP 1.1 and SOAP 1.2

GetSpeech_localhost.pl - Testing GetSpeech on Local Host

soapversion('1.2') and envprefix('soap12') Must Used Together

default_ns() - Setting Default namespace for Body Elements

SOAP::Data - Utility Class to Generate XML Elements

SOAPAction - Not Needed, But No Way to Remove It

Unsupported Media Type: "application/soap"

DEFAULT_HTTP_CONTENT_TYPE='application/soap+xml'

content_type() method in the HTTP::Headers Class

GetSpeech_SOAP_1_2.pl - SOAP::Lite for SOAP 1.2 Web Service

Dr. Herong Yang, updated in 2009
GetSpeech_SOAP_1_2.pl - SOAP::Lite for SOAP 1.2 Web Service