Skip to main content
 首页 » 编程设计

c#之具有可空 double 的 Web 服务响应未正确反序列化

2024年01月01日60linjiqin

我正在调用我们合作伙伴之一的网络服务。我调用它没有问题,我得到了结果。 响应具有可为空的 double 。在 fiddler 中,我在响应的 XML 中看到这些 double 具有值,但不知何故这些字段不会反序列化到我的代理类,因为这些字段在那里的值为 null。

这是我得到的响应 xml 的摘要,id27 中的值不知何故没有序列化,但 id26 中的 bool 值序列化了。为什么?

<extras soapenc:arrayType="ns2:Extra[16]" xsi:type="soapenc:Array"> 
    <extras href="#id1"/> 
    <extras href="#id2"/>            
    ... 
</extras> 
... 
<multiRef id="id1" soapenc:root="0"  
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"  
xsi:type="ns6:Extra" xmlns:ns6="http://model.bookingservice.app.traserv.com"  
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> 
    <assignments xsi:type="ns6:Assignment" xsi:nil="true"/> 
    <category xsi:type="xsd:string">def_Surety</category>            
    ... 
    <orderUnit xsi:type="xsd:string">Verblijf</orderUnit> 
    <payAtLocation href="#id26"/> 
    <price href="#id27"/> 
    <priceNotes xsi:type="xsd:string" xsi:nil="true"/> 
     ... 
</multiRef> 
... 
<multiRef id="id26" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"  
xsi:type="xsd:boolean" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">true</multiRef> 
<multiRef id="id27" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:double" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">345.0</multiRef> 

请您参考如下方法:

我发现 WCF 客户端和 axis webservice 确实存在这些问题。 您可以在代理中解决它,这显然不太好,因为您必须编辑生成的类。或者您可以更改 Web 服务,这也是一个问题,因为您并不总是能控制该服务。

不管怎样,我发现了这些关于它的项目: http://www.tomergabel.com/GettingWCFAndApacheAxisToBeFriendly.aspx

Why won't .NET deserialize my primitive array from a web service?