How to name multiple versioned ServiceContracts in the same WCF service?
- by Tor Hovland
When you have to introduce a breaking change in a ServiceContract, a best practice is to keep the old one and create a new one, and use some version identifier in the namespace.
If I understand this correctly, I should be able to do the following:
[ServiceContract(Namespace = "http://foo.com/2010/01/14")]
public interface IVersionedService
{
[OperationContract]
string WriteGreeting(Person person);
}
[ServiceContract(Name = "IVersionedService", Namespace = "http://foo.com/2010/02/21")]
public interface IVersionedService2
{
[OperationContract(Name = "WriteGreeting")]
Greeting WriteGreeting2(Person2 person);
}
With this I can create a service that supports both versions. This actually works, and it looks fine when testing from soapUI.
However, when I create a client in Visual Studio using "Add Service Reference", VS disregards the namespaces and simply sees two interfaces with the same name. In order to differentiate them, VS adds "1" to the name of one of them. I end up with proxies called
ServiceReference.VersionedServiceClient
and
ServiceReference.VersionedService1Client
Now it's not easy for anybody to see which is the newer version.
Should I give the interfaces different names? E.g
IVersionedService1
IVersionedService2
or
IVersionedService/2010/01/14
IVersionedService/2010/02/21
Doesn't this defeat the purpose of the namespace?
Should I put them in different service classes and get a unique URL for each version?