This section provides a tutorial example on how to use the SOAP::Data class to generate the parameter element with the correct element name. The SOAP::Data class is a utility that allows you generated XML elements with correct name, attributes and sub elements.
I am sure you noticed the issue with the parameter element name, c-gensym3.
The solution is easy as we learned from previous SOAP 1.1 tutorials.
The SOAP::Data class can be used to generate parameters with correct element names:
#- GetSpeech_localhost_SOAP_Data.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',
SOAP::Data->name("Request")
->value("To be, or not to be")
);
Result of GetSpeech_localhost_SOAP_Data.pl:
POST http://localhost/WSShakespeare.asmx HTTP/1.1
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Content-Length: 606
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">
<Request xsi:type="xsd:string">To be, or not to be</Request>
</GetSpeech>
</soap12:Body>
</soap12:Envelope>
The result looks very good. The SOAP::Data class does allow us to control element names.
I think my GetSpeech SOAP 1.2 request XML message is ready now. What do you think?
Of course, I will try to remove the SOAPAction header line.