Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl/Soap lite : "Server was unable to process request. Object reference not set to an instance of an object"

I'm trying to consume a Webservice already existing and that works perfectly. After having read many tutorials and examples, I finally managed to get an answer from the server:

Server was unable to process request. Object reference not set to an instance of an object

The WS simply allows you to get and ID from an NT login (one string param, one string answer).

Here is my perl script:

#!perl -w
use strict;
use warnings;

use LWP::UserAgent; 
use SOAP::Lite on_action => sub { "$_[0]$_[1]"; };
use LWP::Debug; LWP::Debug::level('+'); SOAP::Lite->import(+trace => 'all');
#use SOAP::Lite  +trace =>  'debug';
#sub SOAP::Transport::HTTP::Client::get_basic_credentials { return ('user' => 'pwd') };
use Data::Dumper;

my $var = SOAP::Data->new(name => 'NTLogin', value => "1234", type =>'s:string');

my $resultLogin = SOAP::Lite
  -> uri('http://xxxxx')
  -> proxy('http://yyyyy/zzzzz/directory.asmx')
  -> on_action( sub { join '/', @_ } )
  -> GetUIDFromNTLogin($var);

print "lets test it...\n\n";

  print $resultLogin;
  print "\nresult():\n";
  print $resultLogin->result();

And here's the output:

Launching NT to UID conversion
SOAP::Data::new: ()
SOAP::Lite::new: ()
LWP::UserAgent::new: ()
SOAP::Transport::HTTP::Client::new: ()
SOAP::Lite::call: ()
SOAP::Serializer::envelope: ()
SOAP::Serializer::envelope: GetUIDFromNTLogin SOAP::Data=HASH(0x______)
SOAP::Data::new: ()
SOAP::Data::new: ()
SOAP::Data::new: ()
SOAP::Data::new: ()
SOAP::Data::new: ()
SOAP::Transport::HTTP::Client::send_receive: HTTP::Request=HASH(0x______)
SOAP::Transport::HTTP::Client::send_receive: POST http://yyyyy/zzzzz/directory.asmx
Accept: text/xml
Accept: multipart/*
Content-Length: 534
Content-Type: text/xml; charset=utf-8
SOAPAction: http://tempuri.org/GetUIDFromNTLogin

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:xsi="http://www.w
3.org/1999/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/e
ncoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="
http://www.w3.org/1999/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap
.org/soap/encoding/"><SOAP-ENV:Body><namesp1:GetUIDFromNTLogin xmlns:namesp1="ht
tp://tempuri.org"><NTLogin xsi:type="s:string">1234</NTLogin></namesp1:
GetUIDFromNTLogin></SOAP-ENV:Body></SOAP-ENV:Envelope>
LWP::UserAgent::request: ()
LWP::UserAgent::send_request: POST http://yyyyy/zzzzz/directory.asmx
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::collect: read 441 bytes
LWP::UserAgent::request: Simple response: Internal Server Error
SOAP::Transport::HTTP::Client::send_receive: HTTP::Response=HASH(0x______)
SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 500 Internal Server Error
Cache-Control: private
Date: Mon, 04 Jun 2012 15:54:47 GMT
Server: Microsoft-IIS/6.0
Content-Length: 441
Content-Type: text/xml; charset=utf-8
Client-Date: Mon, 04 Jun 2012 15:54:47 GMT
Client-Peer: 10.94.61.146:80
Client-Response-Num: 1
Set-Cookie: BIGipServer_____________-http=_________________; path=/
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:Body><soap:Fault><faultcode
>soap:Server</faultcode><faultstring>Server was unable to process request. ---&g
t; Object reference not set to an instance of an object.</faultstring><detail />
</soap:Fault></soap:Body></soap:Envelope>
SOAP::Deserializer::deserialize: ()
SOAP::Parser::decode: ()
SOAP::SOM::new: ()
SOAP::Lite::DESTROY: ()
SOAP::Deserializer::DESTROY: ()
SOAP::Transport::DESTROY: ()
SOAP::Transport::HTTP::Client::DESTROY: ()
SOAP::Serializer::DESTROY: ()
SOAP::Data::DESTROY: ()
SOAP::Data::DESTROY: ()
SOAP::Data::DESTROY: ()
SOAP::Data::DESTROY: ()
SOAP::Data::DESTROY: ()
lets test it...

1
result():
SOAP::SOM::DESTROY: ()
SOAP::Data::DESTROY: ()
SOAP::Parser::DESTROY: ()
SOAP::Transport::DESTROY: ()
SOAP::Serializer::DESTROY: ()
SOAP::Deserializer::DESTROY: ()
SOAP::Lite::DESTROY: ()
Press any key to continue . . .

After some research I've done, I've got the impression that the error is on the WS server's side. Yet the WS seems to work perfectly, so I guess something is wrong with my Perl script but I cannot figure out what...

Any help would be very much appreciated !

Thanks,

[Update #1]

Here's the example given by the WS page:

Request

POST /zzzzz/directory.asmx HTTP/1.1
Host: yyyyy
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://xxxxx/GetUIDFromNTLogin"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetUIDFromNTLogin xmlns="http://xxxxx/">
      <NTLogin>string</NTLogin>
    </GetUIDFromNTLogin>
  </soap:Body>
</soap:Envelope>

Response

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetUIDFromNTLoginResponse xmlns="http://xxxxx/">
      <GetUIDFromNTLoginResult>string</GetUIDFromNTLoginResult>
    </GetUIDFromNTLoginResponse>
  </soap:Body>
</soap:Envelope>

[Update #2]

Here's the output to what user1215106 suggested:

<HTML>
<HEAD><TITLE>An Error Occurred</TITLE></HEAD>
<BODY>
<H1>An Error Occurred</H1>
400 Bad Request
</BODY>
</HTML>
like image 731
Will1v Avatar asked May 25 '12 09:05

Will1v


3 Answers

Please test the code below and let us know your experience and output you got.

#!perl -w 

use strict; 
use warnings;
use LWP::UserAgent; 
use SOAP::Lite

use LWP::Debug; LWP::Debug::level('+'); SOAP::Lite->import(+trace => 'all');

print SOAP::Lite 
  -> uri('http://xxxxx') 
  -> proxy('http://yyyyy/zzzzz/directory.asmx') 
  -> on_action(sub { sprintf '"%s"', shift })
  -> on_fault(sub {
       my($soap, $res) = @_; 
       die ref $res ? $res->faultstring : $soap->transport->status, "\n";
     })
  -> GetUIDFromNTLogin(SOAP::Data->type('string')->name('NTLogin')->value(1234))
  -> result;

[UPDATE]

Based on information you posted, I suggest you to execute direct HTTP::Request code, without library SOAP::Lite. Modify the code below with exact information you have:

#!perl -w          

use strict;          
use warnings;

use LWP::UserAgent;
use HTTP::Request;

my $message = '<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><namesp1:GetUIDFromNTLogin xmlns:namesp1="http://tempuri.org"><NTLogin xsi:type="s:string">1234</NTLogin></namesp1: GetUIDFromNTLogin></SOAP-ENV:Body></SOAP-ENV:Envelope>';

my $userAgent = LWP::UserAgent->new();
my $request = HTTP::Request->new(POST => 'http://...');
$request->header(SOAPAction => '"http://tempuri.org/GetUIDFromNTLogin"');
$request->content($message);
$request->content_type("text/xml; charset=utf-8");

my $response = $userAgent->request($request);

if ($response->code == 200) {
  print $response->as_string;
}
else {
  print $response->error_as_HTML;
}
like image 107
Ωmega Avatar answered Oct 21 '22 14:10

Ωmega


“Server was unable to process request. Object reference not set to an instance of an object”

After some research I've done, I've got the impression that the error is on the WS server's side. Yet the WS seems to work perfectly, so I guess something is wrong with my Perl script but I cannot figure out what...

This is definitely a server-side error. It is due to what's arguably a bug in the .NET server code. It's a System.NullReferenceException, easy to reproduce:

D:\temp :: more nr.cs
class Program {
        static void Main() {
                object o = null;
                string s = o.ToString();
        }
}

D:\temp :: csc /nologo nr.cs

D:\temp :: nr.exe

Unbehandelte Ausnahme: System.NullReferenceException:
Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
   bei Program.Main()

This doesn't have anything to do with your SOAP client, only that the client exposes the bug by eliciting the error message.

In a comment on another reply your wrote:

By the way, xxxxx is tempuri.org, which is - I guess - the default address when you write a .Net WS. It's what I can see in the official example anyway, but maybe shouldn't I use this?

It's a wild guess, but a user in another discussion got a NullReferenceException because he didn't supply the correct URL for the SOAPAction header. This is something you could check. Find out what the SOAPAction header is supposed to be and make sure you set it accordingly. If you have access to what's happening server-sice that would help in debugging, of course, because ultimately the bug is clearly server-side.

like image 1
Lumi Avatar answered Oct 21 '22 15:10

Lumi


We all agree that the HTTP 500 server error indicates an error on the server side.

So the first port of call is to retrieve full debugging logs from the WebService Application and send them off to the developer/vendor of that WebService. Report this as a bug in their implementation. Tolerate no nonsense here. Even if your Perl client is passing bad (or missing) data across to the Web Service they should not respond with HTTP 500 Server Error. That's a bug. The error message should put its' arms around the defective client request and give an error message that should read along the lines of, "Ah look here. What's this you're sending me? Didn't I tell you in my lovely documentation that the NTUser has to exist on the system? (or whatever the problem is) Send across that request again but this time send it to me with real data that I can use." The error should be in the HTTP 400 range.

If required, to further backup your case that this is a defect in the Web Service code eliminate your Perl client as being the root cause of the problem by reproducing the error using SOAPUi

You can then share the Soap UI project with the web service developers, it should help them easily find this bug.

like image 1
Rob Kielty Avatar answered Oct 21 '22 14:10

Rob Kielty