Same class comes within different web services
-
25-09-2019 - |
Question
I have 3 different web services work with same class library. These three web services return same class type object. But on the client side, I'm getting 3 different object type even they are same. I can't treat them like one class type.
I think i will add a method which can take object and sets properties with object's props.
Is there any way (somethin like inheritance) ?
Solution
You can use the wsdl.exe tool (this is what Visual Studio does for web references behind the scenes) and pass the /shareTypes
parameter. As long as the types returned by the 3 web services are really the same type, the generated code will contain just one generated class instead of duplicating it for each web service.
wsdl.exe /shareTypes http://server/service1.asmx http://server/service2.asmx etc
OTHER TIPS
Can't you just put the common class(es) into a separate class library project and reference that from each of your three web service projects??
If you need to move around property values, I'd recommend you have a good look at AutoMapper to help you minimize the "monkey code" needed to achieve those assignments.