SOAP Web Service Tutorials - Herong's Tutorial Examples - v5.13, by Herong Yang
Error: Object reference not set to an instance of an object
This section provides a tutorial example to try to use a SOAP 1.2 Web service with a service() call to the WSDL document. The test failed a System.NullReferenceException.
Base previous tests on my local system, I wrote this SOAP::Lite WSDL client program to try to use a SOAP 1.2 Web service:
#- GetSpeech_WSDL_1_2.pl #- Copyright (c) 2009 HerongYang.com. All Rights Reserved. #- All rights reserved # use SOAP::Lite +trace; my $wsdl = 'http://www.xmlme.com/WSShakespeare.asmx?WSDL'; my ($phrase) = @ARGV; #- Creating the SOAP client object my $client = SOAP::Lite->new() ->soapversion('1.2') # set to SOAP 1.2 ->service($wsdl) # set the SOAPAction ->readable(true); # make the XML readable #- Overriding the constant $SOAP::Constants::DEFAULT_HTTP_CONTENT_TYPE = 'application/soap+xml'; #- Calling the Web service my $som = $client->GetSpeech($phrase); my $output = $som->result; print $output . "\n";
But the test result is not good:
herong> GetSpeech_WSDL_1_2.pl "To be, or not to be" POST http://www.xmlme.com/WSShakespeare.asmx HTTP/1.1 Accept: text/xml Accept: multipart/* Accept: application/soap Content-Length: 831 Content-Type: application/soap+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://www.w3.org/2003/05/soap-encoding" xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 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:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 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: 690 Content-Type: application/soap+xml; charset=utf-8 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://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <soap:Fault> <soap:Code> <soap:Value>soap:Receiver</soap:Value> </soap:Code> <soap:Reason> <soap:Text xml:lang="en"> System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at WSShakespeare.Shakespeare.GetSpeech(String Request) --- End of inner exception stack trace --- </soap:Text> </soap:Reason> <soap:Detail /> </soap:Fault> </soap:Body> </soap:Envelope>
What's wrong here? My guess is that the parameter "Request" is under the default namespace, not is synch with the method "GetSpeech".
I cannot to fix this. May be you can.
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
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
First WSDL Test Failed with SOAP::Lite
Downloading and Editing WSDL Document
Testing service() Function Locally
soapversion('1.2') Sets Correct Envelope namespace
►Error: Object reference not set to an instance of an object