Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Serialization and namespaces?

Status
Not open for further replies.

serializer

Programmer
May 15, 2006
143
SE
I am having a problem with deserialization.

I have a c# dll with some classes with a namespace called "Shared". All classes resides within this namespace.

This dll is used by a web service which expose a method that takes a byte array.

A WinForms project is serializing an object that originally comes from the dll. The actual object is coming from the web service as the Winforms project is not using the dll by itself. The WinForms project is using the method to send the byte array to the web service.

The web service deserialize this array into an object. The problem is that is is not recognized as the same object and is therefor returning the correct object - but with null members.

The class that is used to serialization is called "Report". So, at the WinForms end it is referenced as:

webserviceReference.Report

At the webservice end we have:

Shared.Report

It works if I create a reference from the webservice to the webservice itself and only work with those classes. It seems like an ugly workaround.

I assume I can add/manipulate the serialization or deserialization in some way to make the deserialization to be able to deserialize the full object. Perhaps to XmlSerializerNamespaces but I have no idea. Can someone shed some light here?
 
it sounds like the problem is you are interchanging the concepts of serialization and mapping. serialization breaks down the object to transmit over the wire, but it is that object. mapping is the idea of copy/moving the state of one object to another.

now you can serialize the object to a generic form (xml) on the sending end. at the receiving end you could parse the xml to find the values and map these values to another object.

i don't think this would work with binary data, because there is no way (that I know of) to traverse the serialization and pick out values. you need to know the type of the object.

usually in this scenario you have a common set of objects shared between both end points. each end point can then map this common object to whatever it wants.

you would have 3 objects WinForm.Report, WebService.Report and Common.ReportDto (common naming convention). the ReportDto could be located in a separate assembly which both the winform and webserivce project reference. each of these projects would then have an object to map the ReportDto to their respective Report type.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top