简体   繁体   English

Web Service返回具有空字段的对象

[英]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. imp返回的对象不为null。 It's returning an ImplementationResponse, as expected. 它按预期返回ImplementationResponse。 But all of the fields in that object are null. 但该对象中的所有字段都为空。 Which is not expected. 这不是预期的。 The WebService, currently, just returns some constant dummy data. 目前,WebService只返回一些常量虚拟数据。 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. 我想我还应该注意,如果我将null传递给GetValue方法,WebService应该抛出异常。 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? 任何想法,我的环境可能会导致WebService返回一个对象,但是使该对象中的每个值都为空? And somehow 'magically' return this mystery object when it should be throwing an exception? 不知何故,当它应该抛出异常时,“神奇地”回归这个神秘物体?

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. 当生成的代码与Web服务返回的xml之间存在差异时,通常会发生这种情况,因此无法对其进行反序列化。

Grab the wsdl again, regenerate all the proxy classes and try again. 再次获取wsdl,重新生成所有代理类,然后重试。 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. 过去常常发生这种情况,因为Web服务不是由我的团队管理的,我们也不会注意到对服务所做的更改。 We ended up intercepting the soap messages in the web service pipeline for debugging. 我们最终拦截了Web服务管道中的soap消息以进行调试。 Here 'sa 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. 您不需要更改管道中的任何内容,只需抓取soap消息并保存它们,以便稍后进行调试。 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. 无论如何,即使这不是你的问题,我认为这是一件好事。

Are the fields marked with < DataMember()> attributes as they won't serialize otherwise? 字段是否标有<DataMember()>属性,否则它们不会序列化?

<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 https://stackoverflow.com/questions/560370/handling-wcf-proxy-null-return-issue

I suppose I should also note that the WebService should throw an exception if I pass null into the GetValue method 我想我还应该注意,如果我将null传递给GetValue方法,WebService应该抛出异常

You didn't pass null here,you passed in a request object. 你没有在这里传递null,你传入了一个请求对象。

Also, you need be able to debug into the web service to see what's going on there. 此外,您需要能够调试到Web服务以查看其中发生的情况。 I assume you are implementing this internally, since you can set it to constant dummy value. 我假设您在内部实现此功能,因为您可以将其设置为常量虚拟值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM