473,385 Members | 1,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

web service not serializing all object properties

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


Dec 10 '07 #1
3 2098
"Jeremy" <no****@please.comwrote in
news:O#**************@TK2MSFTNGP03.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;
}
}
}
}




--
sp**********@rogers.com (Do not e-mail)
Dec 10 '07 #2
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" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"Jeremy" <no****@please.comwrote in
news:O#**************@TK2MSFTNGP03.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;
}
}
}
}



--
sp**********@rogers.com (Do not e-mail)

Dec 10 '07 #3
"Jeremy" <no****@please.comwrote in
news:#n**************@TK2MSFTNGP03.phx.gbl:
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.

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
>"Jeremy" <no****@please.comwrote in
news:O#**************@TK2MSFTNGP03.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;
}
}
}
}



--
sp**********@rogers.com (Do not e-mail)




--
sp**********@rogers.com (Do not e-mail)
Dec 13 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jakob Bengtsson | last post by:
Hi, I have a form (which cannot be serialized). In the form's code I declare an object like this (never mind the object nor class name, it's for illustration only): Private WithEvents...
6
by: Rein Petersen | last post by:
Hi Folks! Here's a strange behaviour: Without a properties SET accessor (see code below), the property will not serialize. public class myObject {
2
by: Tobias Zimmergren | last post by:
Hi, just wondering what serializing really is, and howto use it? Thanks. Tobias __________________________________________________________________ Tobias ICQ#: 55986339 Current ICQ status: +...
0
by: umhlali | last post by:
I get the following exception when my VB.NET app calls a Java web service that returns an array of objects. The same call works for a single object though. So looks like there is no problem...
6
by: Picho | last post by:
Hi all. I have a webservice and a windows app. both of them reference the same class library called WebServiceTest.Core that defines a class called Class1. the webservice exposes a method...
6
by: kbs | last post by:
Hi, I'm looking for some good examples that illustrate how to code a web service that exposes a custom collection so that the properties of the collection are accessible on the client without...
3
by: axr | last post by:
Having trouble with Serilization of objects that contain members which are of type Interface eg public class SomeClass { ISomeInterface1 itf1; ClassType1 ct1; ISomeInterface2 itf2;
3
dmjpro
by: dmjpro | last post by:
plz send me a good link which can clearify me how the J2EE framework works i want the details information .... plz help thanx
2
by: she_prog | last post by:
I have a class derived from UserControl. I need to serialize an object of this class, but only some properties of it, as not all properties are serializable (some of the properties coming from...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.