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)