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 / December 2007

Tip: Looking for answers? Try searching our database.

web service not serializing all object properties

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeremy - 10 Dec 2007 20:09 GMT
I've created a serializable class and put attributes around all the
properties that should be serialized.  I return the class from a web
service, but my problem is that the wsdl for the web service is only
including the Values poperty, and nothing else.  Also, when the object gets
serialized out, only the Values property gets serialized.  I can't figure
out why.

I've included the serialized output from the webservice and the class code
below:

Webservice serialized return value:

<?xml version="1.0" encoding="utf-8"?>
<Result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://interiorhealth.ca/teleplan/webbroker">
 <Values>
   <ValuePart Name="GENDER">MALE</ValuePart>
   <ValuePart Name="RESPONSE" />
   <ValuePart Name="MESSAGE" />
   <ValuePart Name="TID">000</ValuePart>
   <ValuePart Name="Result">SUCCESS</ValuePart>
   <ValuePart Name="Filename">e45.txt</ValuePart>
 </Values>
</Result>

class code

       [Serializable]
       [System.Xml.Serialization.XmlRoot(Namespace =
"http://mycomp.com/test")]
       public class Result
       {
           private string strUnParsed_m;
           private ValueParts pValues_m;
           private Url pRequest_m;
           private WebResponse pWebResponse_m;

           public enum enResult
           {
               SUCCESS = 1,
               FAILURE = 2,
               EXPIRED_PASSWORD = 3,
               UNKNOWN = 4
           }

           [System.Xml.Serialization.XmlElement("UnParsed")]
           public string UnParsed
           {
               get
               {
                   return strUnParsed_m;
               }
           }

           public ValueParts Values
           {
               get
               {
                   return pValues_m;
               }
           }

           [System.Xml.Serialization.XmlElement("Messages",
IsNullable=true)]
           public string Messages
           {
               get
               {
                   return Values["Msgs"];
               }
           }

           [System.Xml.Serialization.XmlElement("TID")]
           public string TID
           {
               get
               {
                   return Values["TID"];
               }
           }

           [System.Xml.Serialization.XmlElement("ResultText")]
           public string ResultText
           {
               get
               {
                   return Values["Result"];
               }
           }

           [System.Xml.Serialization.XmlAttribute("ValidResult")]
           public bool ValidResult
           {
               get
               {
                   return TID != null && ResultValue != enResult.UNKNOWN;
               }
           }

           [System.Xml.Serialization.XmlAttribute("ResultValue")]
           public enResult ResultValue
           {
               get
               {
                   string strResult = ResultText.ToLower();
                   if (strResult.IndexOf("success") == 0)
                   {
                       return enResult.SUCCESS;
                   }
                   else if (strResult.IndexOf("failure") == 0)
                   {
                       return enResult.FAILURE;
                   }
                   else if (strResult.IndexOf("expired.password") == 0)
                   {
                       return enResult.EXPIRED_PASSWORD;
                   }
                   else
                   {
                       return enResult.UNKNOWN;
                   }
               }
           }

           [System.Xml.Serialization.XmlElement("FileName")]
           public string FileName
           {
               get
               {
                   return Values["FileName"];
               }
           }

           [System.Xml.Serialization.XmlIgnore()]
           public WebResponse WebResponse
           {
               get
               {
                   return pWebResponse_m;
               }
           }

           public Result()
           {
               ...
           }

           private Result(Url pRequest) : this()
           {
               ...
           }

           ...

           [Serializable]
           [System.Xml.Serialization.XmlRoot("ValueParts", Namespace =
"http://mycomp.com/test")]
           public class ValueParts :
System.Collections.Generic.List<ValuePart>
           {
               [System.Xml.Serialization.XmlIgnore()]
               public string this[string strName]
               {
                   get
                   {
                       FindPart pFindPart = new FindPart(strName);
                       ValuePart pPart = this.Find(pFindPart.CheckMatch);

                       string strRetVal = string.Empty;

                       if (pPart != null)
                       {
                           strRetVal = pPart.Value;
                       }
                       return strRetVal;
                   }
               }

               public ValuePart Add(string strName, string strValue)
               {
                   ValuePart pPart = new ValuePart(strName, strValue);
                   this.Add(pPart);
                   return pPart;
               }

               private class FindPart
               {
                   string strName_m;

                   public FindPart(string strName)
                   {
                       strName_m = strName;
                   }

                   public bool CheckMatch(ValuePart pPart)
                   {
                       return strName_m.Equals(pPart.Name);
                   }
               }

           }

           [Serializable]
           [System.Xml.Serialization.XmlRoot("ValuePart", Namespace =
"http://mycomp.com/test")]
           public class ValuePart
           {
               private string strName_m;
               private string stValue_m;

               [System.Xml.Serialization.XmlAttribute()]
               public string Name { get { return strName_m; } set {
strName_m = value; } }

               [System.Xml.Serialization.XmlText()]
               public string Value { get { return stValue_m; } set {
stValue_m = value; } }

               public ValuePart()
               {
               }

               public ValuePart(string strName, string strValue)
               {
                   Name = strName;
                   Value = strValue;
               }
           }

       }

   }
Spam Catcher - 10 Dec 2007 20:30 GMT
> I've created a serializable class and put attributes around all the
> properties that should be serialized.  I return the class from a web
> service, but my problem is that the wsdl for the web service is only
> including the Values poperty, and nothing else.  Also, when the object
> gets serialized out, only the Values property gets serialized.  I
> can't figure out why.

Web services will only serialize public properties. Also in most cases,
readonly properties will not work correctly either. Which properties are
missing?

> I've included the serialized output from the webservice and the class
> code below:
[quoted text clipped - 225 lines]
>
>     }

Signature

spamhoneypot@rogers.com (Do not e-mail)

Jeremy - 10 Dec 2007 20:59 GMT
I'm missing everything except for the Values property.  I don't understand
why they can't be read only properties, but I'll try making setters for
them.

>> I've created a serializable class and put attributes around all the
>> properties that should be serialized.  I return the class from a web
[quoted text clipped - 236 lines]
>>
>>     }
Spam Catcher - 13 Dec 2007 05:01 GMT
> I'm missing everything except for the Values property.  I don't
> understand why they can't be read only properties, but I'll try making
> setters for them.

It's a deserialization issue. When .NET deserializes an object, it
instantiates a new instance of the object. If you have read only
properties, it can't deserialize the object correctly (it can't assign
the value passed over from the client).

A simple fix would be to create a blank setter that does nothing. A bit
retarded but it'll fix your serialization issues.

>>> I've created a serializable class and put attributes around all the
>>> properties that should be serialized.  I return the class from a web
[quoted text clipped - 238 lines]
>>>
>>>     }

Signature

spamhoneypot@rogers.com (Do not e-mail)


Rate this thread:







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.