SOAP Web Service Tutorials - Herong's Tutorial Examples - v5.13, by Herong Yang
NumberToWords Failed - Invalid namespace ""
This section provides a tutorial example on how to use the SOAP::Data class to build the request parameter element with correct element name. But the test failed with an error: Invalid namespace ''.
In the previous tutorial, I learned that the server does not like the parameter name "c-gensym3" generated with SOAP::Lite default setting.
What SOAP::Lite function should I use to fix this issue? Looking at the ActivePerl SOAP::Lite manual again, I found this class:
SOAP::Data You can use this class if you want to specify a value, a name, atype, a uri or attributes for SOAP elements (use value(), name(), type(), uri() and attr() methods correspondingly). For example, SOAP::Data->name('abc')->value(123) will be serialized into <abc>123</abc>, as well as will SOAP::Data->name(abc => 123). Each of them (except the value() method) can accept a value as the second parameter. All methods return the current value if you call them without parameters. The return the object otherwise, so you can stack them.
Based on the above description I revised my test program as NumberToWords_Parameter_Name.pl:
#- NumberToWords_Parameter_Name.pl #- Copyright (c) 2005 HerongYang.com. All Rights Reserved. # use SOAP::Lite +trace; my $client = SOAP::Lite->new(); $client->proxy( 'http://www.dataaccess.com/webservicesserver/NumberConversion.wso'); #- Building the parameter element with name and namespace my $parameter = SOAP::Data ->name("ubiNum") ->value(101); #- Calling the server my $som = $client->NumberToWords($parameter); my $output = $som->result; print $output . "\n";
Here is what I did in this program:
When executing NumberToWords_Parameter_Name.pl, I got this:
herong> NumberToWords_Parameter_Name.pl ... SOAP::Transport::HTTP::Client::send_receive: HTTP::Request=HASH(0x305cb20) SOAP::Transport::HTTP::Client::send_receive: POST http://www.dataaccess.com/webservicesserver/NumberConversion.wso HTTP/1.1 Accept: text/xml Accept: multipart/* Accept: application/soap Content-Length: 437 Content-Type: text/xml; charset=utf-8 SOAPAction: "#NumberToWords" <?xml version="1.0" encoding="UTF-8"?> <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:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <NumberToWords> <ubiNum xsi:type="xsd:int">101</ubiNum> </NumberToWords> </soap:Body> </soap:Envelope> SOAP::Transport::HTTP::Client::send_receive: HTTP::Response=HASH(0x305ffc0) SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 500 Internal Server Error Cache-Control: private, max-age=0 Connection: close Server: Microsoft-IIS/8.0 Content-Length: 392 Content-Type: text/xml; charset=utf-8 Access-Control-Allow-Credentials: true Access-Control-Allow-Headers: content-type Access-Control-Allow-Methods: GET, POST Access-Control-Allow-Origin: http://www.dataaccess.com Client-Response-Num: 1 Strict-Transport-Security: max-age=31536000 Web-Service: DataFlex 18.1 <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <soap:Fault> <faultcode>soap:Server</faultcode> <faultstring>Error processing request: Invalid namespace '' expected 'http://www.dataaccess.com/webservicesserver/'</faultstring> <detail/> </soap:Fault> </soap:Body> </soap:Envelope> ...
Too bad. The call fails again with a different error: Invalid namespace ''. SOAP::Lite is not setting any namespace for SOAP body message. I will try to fix the issue in the next tutorial.
Table of Contents
Introduction to SOAP (Simple Object Access Protocol)
SOAP Message Transmission and Processing
SOAP MEP (Message Exchange Patterns)
PHP SOAP Extension Client Programs
PHP SOAP Extension Server Programs
PHP SOAP Web Service Example - getTemp
Perl SOAP::Lite - SOAP Server-Client Communication Module
Perl Socket Test Program for HTTP and SOAP
►Perl SOAP::Lite for NumberToWords SOAP 1.1 Web Service
NumberToWords Failed - Unexpected Parameter "c-gensym3"
►NumberToWords Failed - Invalid namespace ""
NumberToWords Worked - Setting Namespace and Parameter
Perl SOAP::Lite for SOAP 1.2 Web Services
Java Socket and HttpURLConnection for SOAP
SAAJ - SOAP with Attachments API for Java
SoapUI - SOAP Web Service Testing Tool
WS-Security - SOAP Message Security Extension
WS-Security X.509 Certificate Token
Perl SOAP::Lite for GetSpeech SOAP 1.1 Web Service
Perl SOAP::Lite 0.710 for SOAP 1.2 Web Services
Perl SOAP::Lite 0.710 for WSDL