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 / September 2004

Tip: Looking for answers? Try searching our database.

SoapIgnore attribute ignored.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Benjamin Day - 09 Sep 2004 00:51 GMT
I'm passing classes through a web service.  There are some properties on the
class that I don't need to be serialized and would like to remove them for
performance (size) reasons so I've marked them with the
System.Xml.Serialization.SoapIgnore attribute.

I recompiled and checked what was being sent over the wire.  The ignored
property is still showing up in the xml serialization!

I've attached some sample code that uses XmlSerializer and I get the same
behavior as thru the web service.  (which, I suppose should make a lot of
sense)

Any ideas?  

Thanks,
-Ben

// test method
private void DoSerialize()
{
    TestClass temp=new TestClass();

    XmlSerializer serializer=new XmlSerializer(typeof(TestClass));
   
    StringBuilder sb=new StringBuilder();

    StringWriter stream=new StringWriter(sb);

    serializer.Serialize(stream, temp);

    MessageBox.Show(sb.ToString());           
}

// class to be serialized
using System;
using System.Xml.Serialization;

namespace SoapIgnoreTest
{
    /// <summary>
    /// Summary description for TestClass.
    /// </summary>
    public class TestClass
    {
        public TestClass()
        {   
        }

        public string NotIgnored
        {
            get
            {
                return "NotIgnored";
            }
            set
            {
            }
        }

        [SoapIgnore]
        public string Ignored
        {
            get
            {
                return "Ignored";
            }
            set
            {
            }
        }
    }
}

Signature

http://www.benday.com

Tomas Restrepo \(MVP\) - 09 Sep 2004 02:56 GMT
Benjamin,

> I'm passing classes through a web service.  There are some properties on the
> class that I don't need to be serialized and would like to remove them for
[quoted text clipped - 3 lines]
> I recompiled and checked what was being sent over the wire.  The ignored
> property is still showing up in the xml serialization!

SoapIgnoreAttribute is only taken into account if you're using SOAP RPC
encoding, which it seems you're not using. For literal encoding (which is
the default), use [XmlIgnore] instead.

Signature

Tomas Restrepo
tomasr@mvps.org

Benjamin Day - 09 Sep 2004 03:39 GMT
Thanks.  That was exactly what I needed.  

I was hoping for a sec that I'd found a bug in the serialization namespace.  
:)

-Ben

"Tomas Restrepo (MVP)" wrote:

> Benjamin,
>
[quoted text clipped - 10 lines]
> encoding, which it seems you're not using. For literal encoding (which is
> the default), use [XmlIgnore] instead.

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.