Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Service returning object with null fields

Never seen this one before.

WebService.Implementation imp = new WebService.Implementation();
WebService.ImplementationRequest req = new WebService.ImplementationRequest();
return imp.GetValue(req);

The object that imp returns is not null. It's returning an ImplementationResponse, as expected. But all of the fields in that object are null. Which is not expected. The WebService, currently, just returns some constant dummy data. We've tested this on another developer's machine, works just fine.

I suppose I should also note that the WebService should throw an exception if I pass null into the GetValue method. It doesn't. Not for me.

Any idea what could be wrong with my environment that could make a WebService return an object, but make every value in that object null? And somehow 'magically' return this mystery object when it should be throwing an exception?

like image 424
Xaiter Avatar asked Dec 18 '22 08:12

Xaiter


2 Answers

That usually happens when there's a discrepancy between the generated code and the xml being returned by the web service so it cannot be deserialized.

Grab the wsdl again, regenerate all the proxy classes and try again. Make sure you are sending the correct dummy data.

Update:

This used to happen to me a lot because the web services weren't managed by my team and we wouldn't get any notice of changes made to the service. We ended up intercepting the soap messages in the web service pipeline for debugging. Here's a great resource to get you on your way.

You don't need to change anything in the pipeline, just grab the soap messages and save them so you have debug later. Most of the times it turned out to be just that, a change in the contract. Other times we wouldn't have a contract so there was no way of knowing of changes without catching the envelopes.

Anyway, even if it's not your problem I think it's a good thing to have.

like image 134
Rezlaj Avatar answered Dec 19 '22 20:12

Rezlaj


Are the fields marked with < DataMember()> attributes as they won't serialize otherwise?

<DataMember()> _
Public Property SomeField() As String
    Get
        Return m_strSomeField
    End Get
    Private Set(ByVal value As String)
        m_strSomeField= value
    End Set
End Property

Also, consider using trace viewer to analyse the messages sent between the client and server. For info see:

https://stackoverflow.com/questions/560370/handling-wcf-proxy-null-return-issue

like image 35
Tanner Avatar answered Dec 19 '22 20:12

Tanner