views:

52

answers:

2

Hi In C# (other .Net OOP languages as well), I have 2 webservices. Svc1 returns a complex datatype which becomes the parameter for svc2. Note that it is the same complex type.

Now, I create the 2 proxy classes of these 2 webservices. Which means the same type gets generated twice.

How can I make sure that in 2 proxies only one copy of that type is there? You may assume same or different namespaces of 2 webservices.

Thanks AJ

+1  A: 

Generate the two proxies at the same time:

svcutil http://example.com/svc1?wsdl http://example.com/svc2?wsdl

If the type is really the same (name and namespace) in both services it will generate only a single proxy class for the client.

Yet another possibility is to generate the proxy class for the first service:

svcutil http://example.com/svc1?wsdl

compile the generated .cs file into an assembly for example MyAssembly.dll and use the /reference option when importing the second service:

svcutil /reference:MyAssembly.dll http://example.com/svc2?wsdl

This will look for same types in the WSDL and the supplied assembly.

Darin Dimitrov
neat. will try both approaches. thanks Darin.
AJ
curious though.. in case webservices are in different namespaces, what would be best approach to attain the same?
AJ
You can't attain the same if different namespaces. You will need to manually hack around generated proxies.
Darin Dimitrov
A: 

I've run into a similar issue recently; I haven't tried Darin's advice.

Miguel Castro of IDesign gave a great presentation on "WCF the Manual Way… the Right Way" at the March 2009 DevConnections. In that he showed how to reuse service contracts and proxies. From my notes:

  • One assembly for Service/Data Contracts
    • Shared between client & server
  • One assembly for services
    • Permits changing host and reusing
  • One assembly for proxies
    • Reuse among clients
  • Separate application for hosting
  • Do not use "Add Service Reference"
  • Service (POCO) project references Contracts (interfaces) project and System.ServiceModel
  • Client Proxies assemblies reference Contracts assembly but not Service project
  • Client applications instantiate proxies

Our company hasn't made the move to WCF yet, but this looks like the way to go (to me).

EDIT: I found an article by Mr. Castro on this.

TrueWill