service() Method Returns New Objects

This section provides a tutorial example on show that $client->service() is not updating 'this' object, but returning a new object with the specified WSDL document loaded.

While testing GetExchangeRate_Client.pl, I noticed another interesting behavior of SOAP::Lite 0.710.

The service() is not a true object method. The method is not updating the "this" object. It returns the updated object as a new object. So you need to catch the returning object as a workaround. Here are two calling examples:

# Bad behavior - $client still has the old unchanged object
   $client->service(...)
   
# Workaround - catch the updated object in the return
   $client = $client->service();

Here is a test script to prove this:

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

   print "Test 1: Catch the returning object as workaround...\n";
   my $client = SOAP::Lite->new();
   $client = $client->service(
      'file:///c:/herong/GetExchangeRate_WSDL_11_SOAP_11_RPC.wsdl');
   $result = $client->GetExchangeRate('2007-07-07', 'USD', 'JPY');
   print "Exchange rate is: $result\n";

   print "Test 2: Use service() as an object method...\n";
   my $client = SOAP::Lite->new();
   $client->service(
      'file:///c:/herong/GetExchangeRate_WSDL_11_SOAP_11_RPC.wsdl');
   $result = $client->GetExchangeRate('2007-07-07', 'USD', 'JPY');
   print "Exchange rate is: $result\n";

Here is the execution result of GetExchangeRate_Client.pl:

C:\herong>GetExchangeRate_Client_Error.pl
Test 1: Catch the returning object as workaround...
Exchange rate is: 123.14

Test 2: Use service() as an object method...
A service address has not been specified either by using 
SOAP::Lite->proxy() or a service description)

Conclusion, $client->service(...) method is not updating "this" object. You need to catch the returning object as $client = $client->service(...).

Last update: 2009.

Table of Contents

 About This Book

 Introduction to WSDL 2.0

 WSDL 2.0 Document Structure and Syntax

 WSDL Version 2.0 Part 2: Adjuncts

 WSDL 2.0 Document Examples with SOAP Binding

 WSDL 20 Programming APIs and Testing Tools

 Introduction to WSDL 1.1

 WSDL 1.1 Document Structure and Syntax

 WSDL 1.1 Binding Extension for SOAP 1.1

 soapUI 3.0.1 - Web Service Testing Tool

 WSDL 1.1 and SOAP 1.1 Examples - Document and RPC Styles

 PHP SOAP Extension in PHP 5.3.1

Using WSDL in Perl with SOAP::Lite 0.710

 Introduction of Perl SOAP::Lite 0.710 for WSDL

 Methods on SOAP::Lite 0.710 Client Object

 Calling PRC Methods Defined in WSDL 1.1 Documents

service() Method Returns New Objects

 SOAP::Data - XML Elements as Data Objects

 SOAP::Serializer - Converting Data Objects to XML

 Creating a Data Object for a Single XML Element

 Creating a Data Object for Nested XML Elements

 SOAP::Deserializer - Converting XML to Data Objects

 Calling XML Document Based Web Service

 Using Operation Name as the SOAP Body Element Name

 Using WSDL Document in Java with Axis2 1.4.1

 Using WSDL2Java to Generate Web Service Stub Classes

 WSDL 1.1 Binding Extension for SOAP 1.2

 WSDL 1.1 and SOAP 1.2 Examples - Document and RPC Styles

 SOAP 1.2 Binding - PHP, Java and Perl Clients

 WSDL Related Terminologies

 References

 PDF Printing Version