views:

858

answers:

5

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 each service a unique namespace:

com.xyz.appname.ui.usbo.UserManagement    
com.xyz.appname.ui.usbo.AgencyManagement

The problem I have is that each one of the proxies that are generated contain a new user class. One is located at com.xyz.appname.ui.usbo.UserManagement.user and the other at com.xyz.appname.ui.usbo.AgencyManagement.user. However, the user objects are identical and I would like to treat them as such.

Is there a way that I can somehow reference the user object as one object instead of treating them as two different?

I am using .Net 3.5 to consume the service. The service being consumed is written in Java.

Thanks!!

Edit:

This forum thread got very close to an answer, but the accepted answer ended up being to share types from client and server - which I cannot do because we're crossing platforms (Java to .Net). The real question is, is there a /sharetypes type of parameter for svcutil in WCF?

A: 

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.

Mark Cidade
+2  A: 

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.
leppie
+1  A: 

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.

A: 

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.

Steve Horn
Steve, can you accept this as the answer?
John Saunders
That would be, "yes".
John Saunders
+1  A: 

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.

CJBrew
I was wondering about the url thing, thanks.. +1
Leon van der Walt