S
Stan Yamane
I'm trying to use a web service which sometimes returns
objects which contain null members. However, when
returning those objects, rather than just leaving those
members out of the returned XML, it represents them with
elements with xsi:nil attribute set to "true". (as
apparently allowed in the SOAP 1.1 rules for encoding,
section 5.1) [By default, .NET just leaves out elements
when it wants to return null from a server.
However, .NET can be made to replicate this behavior if
you set the IsNullable flag on the XmlElementAttribute
to "true" for each member you want to return as null]
My problem is that when a generated .NET client receives
this message, rather than unmarshalling it as null, it
calls the default constructor of the object and returns
that object to my client code.
Example fragment:
Normal .NET response:
<ReturnNullObjectInContainerResponse
xmlns="http://tempuri.org/"><ReturnNullObjectInContainerRe
sult /></ReturnNullObjectInContainerResponse>
..NET response w/ IsNullable=true [or from the server I
need to connect to]:
<ReturnNullObjectInContainerResponse
xmlns="http://tempuri.org/"><ReturnNullObjectInContainerRe
sult><TestObject
xsi:nil="true" /></ReturnNullObjectInContainerResult></Ret
urnNullObjectInContainerResponse>
As I understand it, the xsi:nil attribute should cause
the .NET runtime to create the container object and place
a null object inside of it, just as not having the object
should, but this doesn't seem to happen.
Has anyone else run across this and found a workaround?
I've tested this in .NET framework 1.1 and it still seems
to be a problem.
objects which contain null members. However, when
returning those objects, rather than just leaving those
members out of the returned XML, it represents them with
elements with xsi:nil attribute set to "true". (as
apparently allowed in the SOAP 1.1 rules for encoding,
section 5.1) [By default, .NET just leaves out elements
when it wants to return null from a server.
However, .NET can be made to replicate this behavior if
you set the IsNullable flag on the XmlElementAttribute
to "true" for each member you want to return as null]
My problem is that when a generated .NET client receives
this message, rather than unmarshalling it as null, it
calls the default constructor of the object and returns
that object to my client code.
Example fragment:
Normal .NET response:
<ReturnNullObjectInContainerResponse
xmlns="http://tempuri.org/"><ReturnNullObjectInContainerRe
sult /></ReturnNullObjectInContainerResponse>
..NET response w/ IsNullable=true [or from the server I
need to connect to]:
<ReturnNullObjectInContainerResponse
xmlns="http://tempuri.org/"><ReturnNullObjectInContainerRe
sult><TestObject
xsi:nil="true" /></ReturnNullObjectInContainerResult></Ret
urnNullObjectInContainerResponse>
As I understand it, the xsi:nil attribute should cause
the .NET runtime to create the container object and place
a null object inside of it, just as not having the object
should, but this doesn't seem to happen.
Has anyone else run across this and found a workaround?
I've tested this in .NET framework 1.1 and it still seems
to be a problem.