Web服务在整数字段中发送null

| 我正在尝试使用第三方网络服务。返回的字段之一定义为
<s:element name=\"SomeField\" minOccurs=\"0\" maxOccurs=\"1\" type=\"s:int\"/> 
在SOAP响应中,他们将字段发送为
<SomeField/>
这是因为空的xml元素不是有效的整数,导致.Net解串器引发异常。 处理此问题的最佳方法是什么? 我尝试调整wsdl以将字段标记为可为空,这会将生成的字段标记为int吗?但是反序列化器仍然失败。 我可以将端点实现为服务参考或Web服务参考。     
已邀请:
        我认为.Net反序列化器无法解决此问题。 如何将
SomeField
的定义调整为字符串。这种方法可以检查是否为空,但您必须对实际值执行Int32.Parse。
<s:element name=\"SomeField\" minOccurs=\"0\" maxOccurs=\"1\" type=\"s:string\"/> 
访问器可以是:
 void int? GetSomeField()
 {
     if (someField == null) return null;
     return In32.Parse(someField);
 }
    
        您可以将默认值设置为0。这样,如果未设置该值,它将发送0。
<s:element name=\"SomeField\" minOccurs=\"0\" maxOccurs=\"1\" default=\"0\" type=\"s:int\"/> 
    
        这是他们代码中的错误。那不匹配模式。 XMLSpy说:
File Untitled6.xml is not valid.
Value \'\' is not allowed for element <SomeField>.
    Hint: A valid value would be \'0\'.
    Error location: root / SomeField
    Details
        cvc-datatype-valid.1.2.1: For type definition \'xs:int\' the string \'\' does not match a literal in the lexical space of built-in type definition \'xs:int\'.
        cvc-simple-type.1: For type definition \'xs:int\' the string \'\' is not valid.
        cvc-type.3.1.3: The normalized value \'\' is not valid with respect to the type definition \'xs:int\'.
        cvc-elt.5.2.1: The element <SomeField> is not valid with respect to the actual type definition \'xs:int\'.
我通过以下模式实现了这一点:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\">
    <xs:element name=\"root\">
        <xs:annotation>
            <xs:documentation>Comment describing your root element</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
            <xs:element name=\"SomeField\" minOccurs=\"0\" maxOccurs=\"1\" type=\"xs:int\"/> 
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>
以及以下XML:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<root xsi:noNamespaceSchemaLocation=\"Untitled5.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">
    <SomeField/>
</root>
    

要回复问题请先登录注册