Hello.
I've created a web service based on a message contract with a business
partner.
In the schema some elements are optional.
How do I prevent an optional element from being serialized into the response
XML (I don't want it to show up) if the value of the element is a particular
value?
Thanks in advance,
Mike
For reference types (strings, objects, etc), just make the value null -
null references aren't serialized.
For value types, you have to add a "friend" to your code... eg
public int myFoo;
public bool myFooSpecified;
To supress myFoo (which always has a value, which is by default false)
serialization, set myFooSpecified to false (the default). To make it get
serialized, set myFooSpecified to true.
No matter what your value type field (or property) is, a boolean friend
with the same first name and Specified at the end will do the trick.
--------------------
>From: "MikeL" <MichaelLopez@inds.com>
>Subject: Conditional serialization of an element?
[quoted text clipped - 10 lines]
>Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
>Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webservices:5608
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
>
[quoted text clipped - 12 lines]
>
>Mike
MikeL - 14 Mar 2005 19:13 GMT
Thanks for responding, Dan.
It didn't take me long until I figured that one out.
Thanks again,
Mike
> For reference types (strings, objects, etc), just make the value null -
> null references aren't serialized.
[quoted text clipped - 44 lines]
>>
>>Mike