views:

15

answers:

2

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) ?

A: 

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.

marc_s
Very good tool that i didn't know(AutoMapper). Can i send type information of classes within web service parameters or class's attributes?
uzay95
A: 

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
Josh Einstein
Can i write an batch to do this automatically when i build? Because I have one solution 3 projects (Web Service Project, ClassLib behind of Web Service and Application, Client Application(WEB APP)). When i build solution i think i will have to run `wsdl.exe /sharedTypes....` command line again and again. Is there any tool that can do this like Ant ?
uzay95
Sure, you can do it with build events in plain vanilla VS or I'm sure there's a MSBuild task for it. I just don't know what the syntax would be off hand. But you really don't need to re-generate the code on each build, only when the service changes.
Josh Einstein
My MSBuild file: `<?xml version="1.0" encoding="utf-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><servis1>http://localhost:40764/WSHtus.asmx</servis1> <servis2>http://localhost:40764/WSEuclid.asmx</servis2> <servis3>http://localhost:40764/WSBiolab.asmx</servis3> </PropertyGroup> <Target Name="proxyGeneration" > <Exec Command='wsdl.exe /sharetypes /out:"D:\prj\WebService_ClassLib\WSProxy.cs" "$(servis1)" "$(servis2)" "$(servis3)" ' WorkingDirectory="C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64" /> </Target></Project>`
uzay95