Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,

I have to do WCF versioning and also it needs to be backward compatible.
I am using channel factory to create instance of service.

Thanks in advance,
Pushkar

What I have tried:

I tried to create versions of service contract but did not work out as i am using channel factory to create instance of WCF service.

C#
[ServiceContract(Name = "Test", Namespace = "http://Test/ServiceContract/2016/1")]
public interface IMYWCFV1
{
     [OperationContract]
     string GetMessage(int id);
        
     [OperationContract]
     int GetId(string message);
        
}

[ServiceContract(Name = "Test", Namespace = "http://Test/ServiceContract/2016/2")]
public interface IMYWCFV2
{
    [OperationContract]
    string GetMessage(int id);
        
    [OperationContract]
    int GetId(string message);
       
}
Posted
Updated 14-Nov-16 1:34am
v2

1 solution

I'd suggest you start by reading [^] (again)

Creating a new Service contract in a new namespace is just that - a new Service contract...

So forget about this and start with a "fresh mind". Ask yourself: Do I want strict versioning? (read MSDN article) or does lax versioning do the job? (was 100% true for all cases I had over the years). Better you read for yourself and ask for specifics you may don't understand. But some general advice - never remove anything from existing Service contracts, just add. And if message-contracts may change (unlikely if you just use them as DTO's), use interfaces instead and decouple the message contracts from implementation in the same way you'd do with Service contracts.

If you want strict versioning you have to change the clients if you have a new "strict" version, for "lax" versioning you may not change the clients as long as the new contract is "compatible" (=didn't remove anything, just add.) If you then want to use e.g. a new service method from the newer contract on client-side you have to change the clients anyway...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900