I have to consume 2 different web services. Both contain a definition for a \'user\' object.
When I reference the services using \"Add service reference\" I give e
What ended up working for me was to provide the svcutil.exe all WSDL addresses that I needed to generate code from. SVCUTIL will look at all the types from each service and determine automatically which ones are common and should be re-used.
The type that you want to be shared should also have a shared namespace, and that namespace should be called out on each of the webservices that want to share that type.
This is a common situation when consuming webservices with different endpoints from the same provider.
You can use the "wsdl.exe /sharetypes" command line tool to create a shared proxy class that will look at all of the endpoints that you provide, and infer which classes can be 'shared'.
In your example, as long as your user object is identical in both services it will get picked up and included in your new shared proxy class.
It probably makes sense to add this shared proxy class generation step as a build event in your project that way it is always up to date.
You can put the user type in a shared common assembly that both the services and the client project references. Then in the configuration for both service clients, you can choose the option of re-using types in referenced assemblies. That way, you're using the type inthe asssembly rather than a separately generated class.
If you're working with local files you can do the following:
wsdl.exe /sharetypes file://c:\path\to\file.wsdl file://c:\path\to\otherFile.wsdl /namespace:<your namespace> /output:(any switches etc...)
The sharetypes switch requires that you provide URLs to the services, and doesn't work if you simply point wsdl at the files.
the WSDL tool has a parameter.
/sharetypes
Turns on type sharing feature. This feature creates one code file with
a single type definition for identical types shared between different
services (namespace, name and wire signature must be identical).
Reference the services with http:// URLs as command-line parameters
or create a discomap document for local files.