views:

389

answers:

4

Hi,

In our project we are consuming WCF webservices exposed at Central location as services with basicHttpBinding.

In client desktop application we need consume those webservices. I am able to generate proxy class using WSDL.exe.

But, I need to convert data/class given by the webservice into my local class, for that now I am xmlserialzing those class/objects given by webservice and deserializing into my local classes as both classes schema matches exactly same.

Is there any better way that I can follow? or Do I need to assign each property from one class to another?

thanks nRk.

+3  A: 
  • declare class manually instead of generating. This is the most DRY solution.

  • try Automapper

elder_george
Thanks for the early reply,Manually means.. I have lots of classes, that it self takes lot of time.And also check the "Automapper'Thank you.
nRk
+1 for AutoMapper.
Darin Dimitrov
A: 

I've done the serialize/deserialize thing myself just as you had. If your classes have the same properties as the proxy classes you could write a helper method that uses reflection to iterate through the properties of the proxy and set the corresponding properties of your class. As long as the property names are the same, that one method should work on all classes.

Jeremy
A: 

A few thoughts:

  • use assembly sharing via WCF; this allows you to use the same actual assembly at both ends. As long as this is a DTO assembly, this is fine (not hugely portable, though). This is /reference (also /r) in svcutil.exe, or you can do it via the IDE
  • use DataContractSerializer and round-trip (like you are already; just that WCF maps most closely to DataContractSerializer, not XmlSerializer)
Marc Gravell
Thanks.. But onthe client side i am using .net 2.0 only, where i cannot use svcutil.exe.. and DataContractSerializer.
nRk
+1  A: 

If you have control on your local classes (they are not generated code; or you are generating them, yourself) you can use xml attributes to decorate your class, so you can serialize and deserialize it to that xml you work with and you do not have to have specific names for your properties. In addition to this, you may have additional properties on your local class.

If you have not control on defining your local classes, then you have to define a converter or as elder_george mentioned, use AutoMapper.

Using a manual written converter IMO is the fastest way and you can define them as implicit converter operators on your local class.

Kaveh Shahbazian