This section provides a tutorial example on how to generate the GetSpeech request without using the real Web service server - Letting the connection fail with a localhost proxy URL.
Based on previous experience, I know that I need to run many tests while
developing the SOAP 1.2 client program to all GetSpeech at xmlme.com.
Instead of wasting resources at xmlme.com, I will start my client program
with a faked localhost end point to just generate the request.
So here is my first version, GetSpeech_localhost.pl:
#- GetSpeech_localhost.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')
->readable(true)
->proxy('http://localhost/WSShakespeare.asmx');
my $som = $client->call('GetSpeech', "To be, or not to be");
When executing, it will give this output:
\herong>GetSpeech_localhost.pl
...
SOAP::Transport::HTTP::Client::send_receive:
POST http://localhost/WSShakespeare.asmx HTTP/1.1
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Content-Length: 485
Content-Type: application/soap; charset=utf-8
SOAPAction: "#GetSpeech"
<?xml version="1.0" encoding="UTF-8"?>
<Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<GetSpeech>
<c-gensym3 xsi:type="xsd:string">To be, or not to be</c-gensym3>
</GetSpeech>
</Body>
</Envelope>
SOAP::Transport::HTTP::Client::send_receive:
500 Can't connect to localhost:80 (connect: Unknown error)
...
Not too bad. I was able to see the entire request without using a real Web service server. But:
Connection failed as expected, because my localhost is providing any Web service.
$client->readable(true) worked nicely. The request message not a single line any more.
It is properly formatted to be readable.
The SOAPAction header line is in the request. I need to find a way to remove it.
The Content-Type header line is almost correct. "application/soap" should be "application/soap+xml".
The entire request message is under no namespace.
This is wrong. The "Envelope" should have a named namespace of "http://www.w3.org/2003/05/soap-envelope".
The "GetSpeech" should have a default namespace of "http://xmlme.com/WebServices".
The parameter name 'c-gensym3' is wrong. It needs to be set to "Request".