views:

340

answers:

2

hi all,

i've created bunch of classes. i have webservices which reference these classes and contains the classes as parameters and return objects.

when i call the weservice, i have to convert the class to the webservice object else i can type conversion error.

is there a generic way to convert between these types without having to assign the values by hand?

for example

public class person
 fname as string
 lname as string
end class

web service method

public getperson() as person
return new person()
end sub

in the client

dim ws as new webservice

dim person = ws.getperson

i would liek ot be able to call the web service and return the data type back and have a generic coversion instead of as above in stead of:

dim wsPerson as wsReference.Person = ws.getperson()

thanks

+1  A: 

Since the generated proxy class for a web reference is a copy of the interface of the exposed class, you should be able to use reflection to do such conversions.

However, if your classes are not very large or many, I would suggest to manually create a converter that will handle conversion from web service class types to "internal" class types, and the other way around. If the number of classes is large, and if there will be new classes added regularly, or their design change, I would look into making some sort of code generator that will create the converter functionality for you.

Fredrik Mörk
+1  A: 

Some of the advanced features are hard to use from vb.net, but AutoMapper will do the basic translation of Person to Person classes nicely for you.

Dan F