Problems using services which return data using xsi:nil

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.
 
S

Stan Yamane

Found a workaround that seems to work. Thanks.

-----Original Message-----
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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top