suppose i have wcf service running in production pc. just guide me what i need to add in code for giving version to my service.
do i need to maintain version for service contract and data contract separately or not....just give me small example of creating wcf service with at least two version.
if few couple of client are consuming my service and if i change the any existing method of service contract or add few more method to service contract then what will happen....in that kind of situation client can call my service or they need to create proxy again to get the changes in service contract. it will be very helpful if some one discuss all my points with small sample code to get the idea clearly. thanks
There are a few things you need to consider. First you will need to add namespaces to your contracts and schemas/messages. Why? Well because if version 1 and 2 have similar operations and messages they can conflict with each other. Adding namespaces will let the code/client sort of know he is handling 2 different implementations.
Secondly you might want to ask why you want to change a contract of a service. Is it because requirements operations need to be added. Or is it a totally new functionality that can be separated into a new WCF service. If you want to maintain versions, put entirely new functionality into a new service and if it must be a part of the current service, copy the contract and create a separate version.
Changing a contract of a service will break the client that is currently working with that contract. Creating a separate version for the service will allow your current client to keep working with the previous version until you update that client. So you would get something like this.
namespace MyNamespace.Contracts.V1
{
[ServiceContract(Namespace = "urn:company:project:servicename:v1")]
public interface IService
{
[OperationContract]
void RequirementA();
}
}
namespace MyNamespace.Contracts.V2
{
[ServiceContract(Namespace = "urn:company:project:servicename:v2")]
public interface IService
{
[OperationContract]
void RequirementA();
[OperationContract]
void RequirementB();
}
}
Both versions will be hosted separately and your implementation would also be different. However, you can let the implementation delegate your operations to some sort of (business) controller, that supports both versions and your flow will look something like this.
In this way you can have 1 controller handle any (business) logic that need to be executed, preventing any possible duplicate code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With