HighTechTalks DotNet Forums  

web service not serializing all object properties

Dotnet Framework (Webservices) microsoft.public.dotnet.framework.webservices


Discuss web service not serializing all object properties in the Dotnet Framework (Webservices) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Jeremy
 
Posts: n/a

Default web service not serializing all object properties - 12-10-2007 , 03:09 PM






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;
}
}


}


}





Reply With Quote
  #2  
Old   
Spam Catcher
 
Posts: n/a

Default Re: web service not serializing all object properties - 12-10-2007 , 03:30 PM






"Jeremy" <nospam (AT) please (DOT) com> wrote in
news:O#NvEi2OIHA.4584 (AT) TK2MSFTNGP03 (DOT) phx.gbl:

Quote:
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?


Quote:
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;
}
}


}


}







--
spamhoneypot (AT) rogers (DOT) com (Do not e-mail)


Reply With Quote
  #3  
Old   
Jeremy
 
Posts: n/a

Default Re: web service not serializing all object properties - 12-10-2007 , 03:59 PM



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.

"Spam Catcher" <spamhoneypot (AT) rogers (DOT) com> wrote

Quote:
"Jeremy" <nospam (AT) please (DOT) com> wrote in
news:O#NvEi2OIHA.4584 (AT) TK2MSFTNGP03 (DOT) phx.gbl:

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:

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;
}
}


}


}








--
spamhoneypot (AT) rogers (DOT) com (Do not e-mail)



Reply With Quote
  #4  
Old   
Spam Catcher
 
Posts: n/a

Default Re: web service not serializing all object properties - 12-13-2007 , 12:01 AM



"Jeremy" <nospam (AT) please (DOT) com> wrote in
news:#nhXW#2OIHA.4136 (AT) TK2MSFTNGP03 (DOT) phx.gbl:

Quote:
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.


Quote:
"Spam Catcher" <spamhoneypot (AT) rogers (DOT) com> wrote in message
news:Xns9A029DC44FEE7usenethoneypotrogers (AT) 127 (DOT) 0.0.1...
"Jeremy" <nospam (AT) please (DOT) com> wrote in
news:O#NvEi2OIHA.4584 (AT) TK2MSFTNGP03 (DOT) phx.gbl:

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:

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;
}
}


}


}








--
spamhoneypot (AT) rogers (DOT) com (Do not e-mail)





--
spamhoneypot (AT) rogers (DOT) com (Do not e-mail)


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.