Problems using services which return data using xsi:nil

Discussion in 'ASP .Net Web Services' started by Stan Yamane, Jul 14, 2003.

  1. Stan Yamane

    Stan Yamane Guest

    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.
     
    Stan Yamane, Jul 14, 2003
    #1
    1. Advertising

  2. Stan Yamane

    Stan Yamane Guest

    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"

    /></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.
    >
    >.
    >
     
    Stan Yamane, Jul 15, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Prange
    Replies:
    0
    Views:
    7,152
    Stefan Prange
    Mar 16, 2005
  2. xsi nil=true

    , Apr 25, 2005, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    273
  3. Jaime Stuardo

    xsi:nil="true" in parameter definition?

    Jaime Stuardo, Oct 6, 2005, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    301
    Jaime Stuardo
    Oct 6, 2005
  4. emil

    soap xsi:nil="true" problem for multi level objects

    emil, Oct 31, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    317
  5. Christoffer Sawicki
    Replies:
    5
    Views:
    287
    Christoffer Sawicki
    Sep 2, 2006
Loading...

Share This Page