Use the /sharetypes when calling wsdl.exe :
/ sharetypes Enables type sharing. This function creates one code file with the definition of one type for identical types shared between other services (namespace, name and proxy signature must be identical). Link to services with http: // URLs as command line parameters or create a discomap document for local files.
If the classes match exactly, they should be generated only once, if you generate code for both services in one command. Both services will use the same class, so no conversion is required.
Edit:
If the XML namespaces do not match (which is common), .NET will treat them as different types, and rightly so. You will either have to fix the web services so that the types are exactly the same (recommended) or do the conversion between the two generated types. This will lead to a big boring property assignment code, so you might want to use something like AutoMapper to handle the conversion for you.
wsdl.exe should generate partial classes , so if you want, you can define implicit conversions between different types:
public static implicit operator addressTO1(addressTO source) { addressTO1 result = new addressTO1();
I'm usually not a big fan of implicit conversions, but in this case it may be justified.
source share