Tags

,

Introduction

  • Versioning
  • Versioning Strategies
  • Add Member
  • Delete Member
  • Parameter Data Type Change
  • Return Type Change
  • New Method

Versioning

In a software product/project the changes in the requirements are always unavoidable. We should not restrict the customer by saying no to the changes, but we should welcome them with the right set of techniques and the processes to respond the changes. The changes in the requirements might cause a change in the operation, service or in the structure of data being exchanged. In the result it causes a change in the WSDL document that leads us to a new version of Data Contract. In simple words, once the service is ready and it is deployed to production, any changes in the contracts should be backwards compatible, so that the existing clients would not be affected once the changes are deployed. In this article we will discuss the techniques and procedures to achieve this versioning facility.

Versioning Strategies

In this article we will discuss the following basic versioning strategies:

  • Adding a new parameter to the operation signature
  • Removing parameters from an operation signature
  • Modifying parameter types of operations
  • Modifying the return value of a service method
  • Adding new service method in a service

Adding New Parameter to the Operation Signature

addnewparam

Please look at the preceding snapshot, you can find only three arguments for this service method and this snapshot had been taken before the service method is changed.
Based on the requirement changes, the service method gets an additional parameter called iDiscountAmount. As in the following snapshot the service method is changed with an additional parameter.

vers1

What would happen to the clients still having the old reference of the service? No problem, the client will remain unaffected. When the service is called by the old method signature, the service will initialize the new parameters with a default value, in our case the additional parameter data type is an integer whose default value will be “0″. The client will not be disturbed because of the iDiscountAmount parameter that remains unaffected. And the final output will be:

Final Output

Removing Parameters from an Operation Signature

Removing Parameters

Please look at the preceding snapshot, you can find three arguments for this service method and this snapshot had been taken before the service method is changed. Based on the requirements changes, the service method removes the parameter called sDeliveryLocation. As in the following snapshot the service method removed the parameter

Parameter in Service Method

In this case, the client will be sending surplus parameters since he is holding the old service reference, but the surplus parameters are ignored at the service level and this results in data lost at the service. So the client still remains unaffected with the following output:

New Output

Modifying Parameter Types of Operations

Modifying Parameter

Please look at the preceding snapshot, you can find one string data type argument for this service method and this snapshot had been taken before the service method is changed. Based on the requirements changes, the service method changed the parameter type from string to integer. As in the following snapshot the service method changed the data type of the parameter.

Changed DataType in Servvice Method

If we run the client without updating the service reference, the result is unexpected. In our case the string data type could be sent through the switch case, then no matching cases were available so it returns an empty string. The final output will be shown below:

Changed Final Output

Modifying the Return Value of a Service Method

In our case if you find the attached source code the client is actually expecting the string as the return value, but the current service implementation returns an array list. If we run the client without updating the service reference, the result is unexpected.

Adding New Service Method in a Service

Changed Service Method

The preceding one is the new method added in the service that is completely unknown to the client because he is still holding the old service reference. So the client remains unaffected.

Attachment

Refer the attached source code for further details

SourceCode

Summary

WCF is version-tolerant, the framework tries its best to serve existing clients with backward compatibility.

Advertisements