C # class referenced by a web service not properly deserializing

I have a web service that serializes a class (a class from a web service) in MSMQ , then it checks the windows queue and deserialization service. The Windows service has a web link to get the class.

If I deserialize inside the web service, everything will be fine. However, when I deserialize from a Windows service, everything works, with the exception of two string arrays that exit as null, so I believe that something is not being passed properly through the web link.

Here is a snippet from the class in question:

[Serializable, XmlInclude(typeof(EmailType))] public partial class Email { [System.Xml.Serialization.XmlElement("BodyParameters")] public string[] BodyParameters { get { return this.bodyParameters; } set { this.bodyParameters = value; } } [System.Xml.Serialization.XmlElement("SubjectParameters")] public string[] SubjectParameters { get { return this.subjectParameters; } set { this.subjectParameters = value; } } } 

The Reference.cs file that I get in my Windows service is as follows:

 /// <remarks/> [System.Xml.Serialization.XmlElementAttribute("BodyParameters")] public string[] BodyParameters { get { return this.bodyParametersField; } set { this.bodyParametersField = value; } } /// <remarks/> [System.Xml.Serialization.XmlElementAttribute("SubjectParameters")] public string[] SubjectParameters { get { return this.subjectParametersField; } set { this.subjectParametersField = value; } } 

Is there any special way that I have to refer to a class or tweak the string [] in the class for the correct link?

Here I get the output if I serialize to a file:

 <?xml version="1.0" encoding="utf-8"?> <Email xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" MessageType="None" PackageID="0" To=" asdf@asdf.com " Subject="testing..." Body="this is a test" IsHTML="false"> <BodyParameters>one two</BodyParameters> <BodyParameters>three four</BodyParameters> <BodyParameters>test test</BodyParameters> <SubjectParameters>foo</SubjectParameters> </Email> 

Keep in mind that everything except BodyParameters and SubjectParameters is great for a Windows service. Web service, everything works.

+4
source share
2 answers

I came across this many years ago when developing a layered application. I hope your situation is the same as mine, so it will be useful.

Our setup was that we had one server, intended only for servicing web services for transferring data between all other components.

Classes were defined in the web service project. Example:

 <Serializable()> _ Public Class RetailInformation_StoreInformation ... End Class 

When we had a client class, try to deserialize the serialized data, we could not do that. We tried to copy the DLL containing the RetailInformation_StoreInformation class to client applications, but that would just not deserialize.

In the end, we discovered this.

Say we have a client application called StoreInfoDisplayApp

In the StoreInfoDisplayApp project, we added a web link to a web service called RetailInfoService.

We found that we cannot deserialize the RetailInformation_StoreInformation from the dll as follows:

 Private Function DeSerializeStoreInfo(ByVal path As String) As RetailInformation_StoreInformation Dim ser As New System.Xml.Serialization.XmlSerializer(GetType(RetailInformation_StoreInformation)) Dim reader As System.IO.Stream = File.OpenRead(path) Dim returnvalue As RetailInformation_StoreInformation = CType(ser.Deserialize(reader), RetailInformation_StoreInformation) reader.Close() Return returnvalue End Function 

because the compiler (or the runtime is foggy) viewed this as StoreInfoDisplayApp.RetailInformation_StoreInformation

Instead, we had to change all instances

RetailInformation_StoreInformation

to

RetailInfoService.RetailInformation_StoreInformation

to indicate that the type we are deserializing was the same type that the web service served. Then it worked like a peach!

+1
source

You need to put [XmlArray] in the SubjectParameters property, like this

 [System.Xml.Serialization.XmlArrayAttribute(ElementName="SubjectParameters")] public string[] SubjectParameters { get { return this.subjectParametersField; } set { this.subjectParametersField = value; } } 
+1
source

All Articles