Web 服务在整数字段中发送 null
我正在尝试使用第三方网络服务。返回的字段之一定义为
<s:element name="SomeField" minOccurs="0" maxOccurs="1" type="s:int"/>
在 SOAP 响应中,他们将字段发送为
<SomeField/>
这会导致 .Net 反序列化器抛出异常,因为空 xml 元素不是有效的整数。
处理这个问题的最佳方法是什么?
我尝试调整 wsdl 将字段标记为可为空,这确实将生成的字段标记为 int?但解串器仍然失败。
我可以将端点实现为服务引用或 Web 服务引用。
I am trying to use a 3rd party webservice. One of the fields that is returned is defined as
<s:element name="SomeField" minOccurs="0" maxOccurs="1" type="s:int"/>
In the SOAP response they send the field as
<SomeField/>
This is causes the .Net deserializer to throw an exception as the empty xml element is not a valid integer.
What is the best way to handle this?
I have tried tweaking the wsdl to mark the field as nullable which does marked the generated fields as int? but the deserializer still fails.
I can implement the endpoint as either a service reference or as a web service reference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为 .Net 反序列化器无法处理这个问题。
将
SomeField
的定义调整为字符串怎么样?这种方式可以检查空值,但您必须对实际值执行 Int32.Parse 。访问器可以是:
I don't think the .Net deserialiser can cope with this.
How about tweaking the definition of
SomeField
to a string. This way can check for a null, but you would have to do an Int32.Parse to the real value.The accessor could be:
您可以将默认值设置为 0。这样,如果未设置该值,它将发送 0。
You could set the default to 0. That way if the value is not set it will send 0.
这是他们代码中的一个错误。这与架构不匹配。 XMLSpy 说:
我通过以下模式得到了它:
和以下 XML:
This is a bug in their code. That does not match the schema. XMLSpy says:
I got that with the following schema:
and the following XML: