Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / March 2005

Tip: Looking for answers? Try searching our database.

Conditional serialization of an element?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MikeL - 17 Feb 2005 20:10 GMT
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
Dan Rogers - 08 Mar 2005 00:55 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.