This section provides a tutorial example on how to set Body sub elements under a default namespace of any specified URI - Using the default_ns() function.
The next issue is to set a default namespace of "http://xmlme.com/WebServices"
as required by the GetSpeech Web service document.
I used the following test program to test the default_ns() function:
#- GetSpeech_localhost_default_ns.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')
->envprefix('soap12')
->default_ns('http://xmlme.com/WebServices')
->readable(true)
->proxy('http://localhost/WSShakespeare.asmx');
my $som = $client->call('GetSpeech', "To be, or not to be");
Result of GetSpeech_localhost_default_ns.pl:
POST http://localhost/WSShakespeare.asmx HTTP/1.1
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Content-Length: 610
Content-Type: application/soap; charset=utf-8
SOAPAction: "http://xmlme.com/WebServices#GetSpeech"
<?xml version="1.0" encoding="UTF-8"?>
<soap12:Envelope
xmlns:soap12="http://www.w3.org/2003/05/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:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap12:Body>
<GetSpeech xmlns="http://xmlme.com/WebServices">
<c-gensym3 xsi:type="xsd:string">To be, or not to be</c-gensym3>
</GetSpeech>
</soap12:Body>
</soap12:Envelope>
The result looks very good. default_ns() did set the GetSpeech element
under the default namespace of the specified URI.
Notice that the default namespace URI also used by the SOAPAction header line.