This section provides a tutorial example on how to use the service() function to WSDL to call a Web service. Test failed with incorrect Envelope namespace.
According to SOAP::Lite 0.710 manual, WSDL is supported with the service() function.
Since get GetSpeech Web service provides WSDL at http://www.xmlme.com/WSShakespeare.asmx?WSDL,
I wrote my first SOAP::Lite WSDL client program like this:
#- GetSpeech_WSDL_Test.pl
#- Copyright (c) 2009 by Dr. Herong Yang, herongyang.com
#- All rights reserved
#
use SOAP::Lite +trace;
my $result = SOAP::Lite
->service('http://www.xmlme.com/WSShakespeare.asmx?WSDL')
->readable('true')
->GetSpeech('To be, or not to be');
The code looks simple. But it is not working:
POST http://www.xmlme.com/WSShakespeare.asmx HTTP/1.1
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Content-Length: 831
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://xmlme.com/WebServices/GetSpeech"
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="http://xmlme.com/WebServices">
<soap:Body>
<tns:GetSpeech>
<Request xsi:type="s:string">To be, or not to be</Request>
</tns:GetSpeech>
</soap:Body>
</soap:Envelope>
...
HTTP/1.1 500 Internal Server Error
Cache-Control: private
Connection: close
Date: ... 2009
Server: Microsoft-IIS/6.0
Content-Length: 1106
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="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<soap12:Upgrade
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:SupportedEnvelope qname="soap:Envelope"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" />
<soap12:SupportedEnvelope qname="soap12:Envelope"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" />
</soap12:Upgrade>
</soap:Header>
<soap:Body>
<soap:Fault>
<faultcode>soap:VersionMismatch</faultcode>
<faultstring>
System.Web.Services.Protocols.SoapException:
Possible SOAP version mismatch:
Envelope namespace http://schemas.xmlsoap.org/wsdl/soap/
was unexpected.
Expecting http://schemas.xmlsoap.org/soap/envelope/.
at System.Web.Services.Protocols.SoapServerProtocol.CheckHelperVersion
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest(
</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
The error message tells me that:
The namespace for the Envelope is wrong. I need to find out
why "http://schemas.xmlsoap.org/wsdl/soap/" is used as the Envelope namespace.
'Content-Type: text/xml; charset=utf-8' in the request tells me
that SOAP 1.1 was used as the default.
'SOAPAction: "http://xmlme.com/WebServices/GetSpeech"' in the request
was correctly generated.
'<Request xsi:type="s:string">To be, or not to be</Request>' in request
was correctly generated.