Can I change the WCF ServiceContract interface namespace without changing the service?

Is there a way to change the .NET namespace of the WCF ServiceContract interface, but still make the WCF service backward compatible with clients that use the old (identical, except for the namespace) ServiceContract? For example, suppose I have (in vb.net):

Namespace MyCompany.MyPoorlyNamedProject <ServiceContract(Name:="ThingService")> _ <CLSCompliant(True)> _ Public Interface IThingService ... End Interface EndNamespace 

And I want to change this to

 Namespace MyCompany.MyProject <ServiceContract(Name:="ThingService")> _ <CLSCompliant(True)> _ Public Interface IThingService ... End Interface End Namespace 

No service change at all.

I tried only this way, but my xsds referenced from wsdl show a new namespace name that seems incompatible.

Any ideas?

+8
wcf servicecontract
source share
1 answer

As long as the name and (XML) namespace of your service contract do not change - a must! WCF services really do not care about the internal components of .NET as they are implemented.

This works as long as the client side joins your service using the standard Add Service Reference method (polling service metadata to create a separate proxy server on the client side) - in this case, the proxy server on the client side has no knowledge of any namespaces .NET on the service side ... you can change them on the service side and redeploy your service files - the client will continue to work.

The only thing you need to do to configure is the configuration of your service (in web.config , if you host in IIS, in the host app.config otherwise):

  • The <service> attribute of the name= tag has the fully qualified class name of the .NET application (including the .NET namespace)

  • The <endpoint> attribute of the contract= tag has the fully qualified domain name of the .NET service (including the .NET namespace) containing the service contract

This does not work, obviously, if you share the general assembly with the service contract - in this case the client side will be bound to the .NET namespace of these contract files in the general assembly, and if these changes are changed, the client will no longer work.

+12
source share

All Articles