GetSpeech Worked - Using SOAP::Data Class and on_action() Function

This section provides a tutorial example on how to use the SOAP::Data class to build the request parameter element with correct element name and a namespace. My first SOAP::Lite program works now with the GetSpeech Web service.

In the previous tutorial, I confirmed that the parameter name "c-gensym3" generated with SOAP::Lite default setting is the root cause of the exception of "System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object."

What SOAP::Lite function should I use to fix this issue? Looking at the ActivePerl SOAP::Lite manual again, I found this class:

   You can use this class if you want to specify a value, a name, 
   atype, a uri or attributes for SOAP elements (use value(), name(), 
   type(), uri() and attr() methods correspondingly). For example, 
   SOAP::Data->name('abc')->value(123) will be serialized into 
   <abc>123</abc>, as well as will SOAP::Data->name(abc => 123). Each 
   of them (except the value() method) can accept a value as the 
   second parameter. All methods return the current value if you call 
   them without parameters. The return the object otherwise, so you 
   can stack them.

Based on the above description I revised my test program as

#- Copyright (c) 2009 All Rights Reserved.
#- All rights reserved
   use SOAP::Lite +trace;
   my $client = SOAP::Lite->new();

#- Fixing the SOAPAction header line - join uri and method name with /
   $client->on_action(sub { join '/', @_ });

#- Building the parameter element with name and namespace
   my $parameter = SOAP::Data
        ->value("To be, or not to be");

#- Calling the server
   my $som = $client->GetSpeech($parameter);
   my $output = $som->result;
   print $output . "\n";

Here is what I did in this program:

When executing, I got this:

Accept: text/xml
Accept: multipart/*
Content-Length: 597
Content-Type: text/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
    <namesp1:GetSpeech xmlns:namesp1="">
      <namesp2:Request xsi:type="xsd:string"
        To be, or not to be
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Connection: close
Date: ... 2009
Server: Microsoft-IIS/6.0
Content-Length: 1942
Content-Type: text/xml; charset=utf-8
Client-Date: ... 2009
Client-Peer: ...
Client-Response-Num: 1
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap=""
    <GetSpeechResponse xmlns="">
        <SPEAKER>HAMLET</SPEAKER>To be, or not to be: 
        that is the question: Whether 'tis nobler in the mind

Bingo! I got my first SOAP::Lite program working with GetSpeech Web service provided by

Table of Contents

 About This Book

 Introduction to Web Service

 Introduction to SOAP (Simple Object Access Protocol)

 SOAP Message Structure

 SOAP Message Transmission and Processing

 SOAP Data Model

 SOAP Encoding

 SOAP RPC Presentation

 SOAP Properties Model

 SOAP MEP (Message Exchange Patterns)

 SOAP HTTP Binding

 SOAP PHP Implementations

 PHP SOAP Extension Client Programs

 PHP SOAP Extension Server Programs

 PHP SOAP Web Service Example - getTemp

 SOAP Perl Implementations

 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

 Perl SOAP::Lite for WSDL

 Python SOAP Client: Zeep

 SOAP Java Implementations

 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

 GetSpeech Failed - Incorrect SOAPAction Header Line

 GetSpeech Failed - Incorrect Parameter Name c-gensym

 Using Socket Program to Request Parameter Name

GetSpeech Worked - Using SOAP::Data Class and on_action() Function - SOAP::Lite for SOAP 1.1 Web Service

 Perl SOAP::Lite 0.710 for SOAP 1.2 Web Services

 Perl SOAP::Lite 0.710 for WSDL

 Web Services and SOAP Terminology

 Archived Tutorials


 Full Version in PDF/EPUB