0

So I have a PHP Soap service that is running nusoap and I am writing custom responses.

The php client works perfectly but C# client keeps returning this:

Object reference not set to an instance of an object.

Any ideas on how to troubleshoot this problem?

I've tried initializing every variable with with test data, but I keep getting the same error.

Thanks for your input.

I am using this method.

http://my.execpc.com/~gopalan/dotnet/webservices/webservice_csharp_client.html

This is the error I receive ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object at gt.MainClass.Main (System.String[] args) [0x0005a] in //Projects/gt/Main.cs:27

line 27 (gt is the wsdl object)

gt.Transact(trans) which I am passing a transaction object and it should return a transaction response,but it appears to not be parsing the response.

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://CANNOT TELL YOUt", RequestNamespace="CANNOT TELL YOU", ResponseNamespace="CANNOT TELL YOU",

This is the method being called and this is a piece of code from the partial class.

ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped, Use=System.Web.Services.Description.SoapBindingUse.Literal)] [return: System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] public TransactResponse Transact([System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] TransactRequest request) { object[] results = this.Invoke("Transact", new object[] { request}); return ((TransactResponse)(results[0])); }

MrNemus
  • 289
  • 1
  • 4
  • 12
  • 2
    we'll definitely need some code. At the very least, the line that throws the exception. – xbonez Jan 12 '12 at 19:43
  • 2
    Are you adding a "Web Reference" to it *(if using VS)*? Or are you creating your own proxy? – user1231231412 Jan 12 '12 at 19:46
  • http://my.execpc.com/~gopalan/dotnet/webservices/webservice_csharp_client.html – MrNemus Jan 13 '12 at 18:00
  • I am not sure what the difference is between the two. – MrNemus Jan 13 '12 at 18:11
  • The content type text/xml; charset=UTF-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. So I guess the issue is how do I change binding in nusoap? – MrNemus Jan 13 '12 at 19:11
  • so after reading this http://stackoverflow.com/questions/945922/nusoap-how-to-change-content-type-of-request I changed the content type. Now I receive Unhandled Exception: System.InvalidOperationException: Not supported Content-Type in the response: 'application/soap+xml; charset=utf-8' – MrNemus Jan 13 '12 at 21:18
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – tom redfern Jan 11 '17 at 10:30

1 Answers1

0

This error was due to xml formatting of the response.

So in this scenario I was taking a wsdl generated by C# ASP.NET and running that wsdl with nusoap on a php5 apache server. (This was do to a client's request to re implement an existing service so they didn't have to change their code.)

So for example if you have

<SomeResponse xmlns='some url'>
   < object>
       <element>data</element >
   </object>
</SomeResponse >

It needs to be formatted like this for .net to parse the xml correctly.

<SomeResponse xmls='some url'>
<SomeResult xmlns:a='some url' xmlns:i=''>
   <a:object>
    <a:element></a:element>
 </a:object>
</SomeResult>
</SomeResposne>

So it looks like the response data needs to be encapsulated by a Result tag which is the concatenation of the function name with the string "Result". So in the example above the function being called is the "Some" function.

I am not a xml or soap expert and I am not sure exactly why this is. I know it has to do with the xmlns:a='some url' tag.

if anyone could explain it better that would be great.

MrNemus
  • 289
  • 1
  • 4
  • 12