开发者

.NET 2.0 Web service creating new objects when null supplied via soap

开发者 https://www.devze.com 2023-03-20 20:55 出处:网络
I have an ASP.NET 2.0 web service and am using it in (among other things) an Adobe Flex application. I have a strange issue where if I send an object to the web service using soap with some fields tha

I have an ASP.NET 2.0 web service and am using it in (among other things) an Adobe Flex application. I have a strange issue where if I send an object to the web service using soap with some fields that are null the webservice is actually creating new objects on the other end (and not putting any data in them).

The XML being sent looks like this:

 <tns:Item>
            <tns:Id>-1</tns:Id>
            <tns:SomeField>21114</tns:SomeField>
            <tns:SomeFieldThatShouldBeNull xsi:nil="true"/>
            <tns:SomeFieldThatShouldBeNull2 xsi:nil="true"/>
</tns:Item>

In 开发者_JS百科this example SomeFieldThatShouldBeNull and SomeFieldThatShouldBeNull2 are being created as new objects by the webservice. It is vital for the application that does not happen. What could be causing this?

Google, MSDN and the ASP.NET forums have not come up trumps so far.


Fixed by random prodding. It seems that I have to put the following attribute on the field in the .NET code to get it to treat a field with an xsi:nil="true" attribute as a null value:

[System.Xml.Serialization.XmlElementAttribute(IsNullable = true)]
0

精彩评论

暂无评论...
验证码 换一张
取 消