Once services are hosted to production, their associated WSDL documents – which describe service endpoints, protocols and related contracts – must not be changed. Or, at a minimum, any changes should be backward compatible so that existing clients are not affected when changes are published. followings are the few versioning strategies that you might consider for your WCF applications.
Service contracts and backward compatibility
Adding new parameters to an operation signature :
If we add more parameters in operation contract client will be unaffected and new parameter will be initialize with default value
In following example if we add one more parameter in operation contract signature, whereas client has implemented it with one parameter, client will be unaffected and newParameter will be initialize with default value.
[OperationContract]
Employee getEmoloyee(int id);
[OperationContract]
Employee getEmoloyee(int id, string newParameter);
Removing parameters from an operation signature :
Client will be unaffected. Superfluous parameters pass by clients are ignored, extra data lost at the service.
[OperationContract]
Employee getEmoloyee(int id);
[OperationContract]
Employee getEmoloyee();
Modifying parameter types :
An exception will occur if the incoming type from the client cannot be converted to the parameter data type.
[OperationContract]
Employee getEmoloyee(int id);
[OperationContract]
Employee getEmoloyee(Datetime id);
Above signature change from integer to datetime affect client and throw exception at run time because integer is not compatible with datetime but below operation contract signature will work.
[OperationContract]
Employee getEmoloyee(double id);
Modifying return value types :
An exception will occur if the return value from the service cannot be converted to the expected data type in the client version of the operation signature.
Adding new operations :
Client unaffected. Will not invoke operations it knows nothing about.
Removing operations :
An exception will occur. Messages sent by the client to the service are considered to be using an unknown action header.
Add new non-required members :
Client unaffected. Missing values are initialized to defaults.
Add new required members :
An exception is thrown for missing values.
Remove non-required members:
Data lost at the service. Unable to return the full data set back to the client, for example. No exceptions.
Remove required members:
An exception is thrown when client receives responses from the service with missing values.
Modify existing member data types:
If types are compatible no exception but may receive unexpected results.
Related Post :
Different-option-of-hosting-wcf-service
Binding-in-wcf-choosing-right-wcf
Exchanging-metadata-in-wcf
Some-interesting-facts-about-data-contract
Knowntype-attribute-in-wcf
Associating-knowntype-in-wcf
Message-contract-in-wcf
Exception-handling-in-wcf
Exception Handling in WCF - SOAP Fault in WCF
Exception Handling in WCF - Unhandled Exception in WCF
Exception Handling in WCF - Creating and Throwing Strongly Typed SOAP Fault
Service contracts and backward compatibility
Adding new parameters to an operation signature :
If we add more parameters in operation contract client will be unaffected and new parameter will be initialize with default value
In following example if we add one more parameter in operation contract signature, whereas client has implemented it with one parameter, client will be unaffected and newParameter will be initialize with default value.
[OperationContract]
Employee getEmoloyee(int id);
[OperationContract]
Employee getEmoloyee(int id, string newParameter);
Removing parameters from an operation signature :
Client will be unaffected. Superfluous parameters pass by clients are ignored, extra data lost at the service.
[OperationContract]
Employee getEmoloyee(int id);
[OperationContract]
Employee getEmoloyee();
Modifying parameter types :
An exception will occur if the incoming type from the client cannot be converted to the parameter data type.
[OperationContract]
Employee getEmoloyee(int id);
[OperationContract]
Employee getEmoloyee(Datetime id);
Above signature change from integer to datetime affect client and throw exception at run time because integer is not compatible with datetime but below operation contract signature will work.
[OperationContract]
Employee getEmoloyee(double id);
Modifying return value types :
An exception will occur if the return value from the service cannot be converted to the expected data type in the client version of the operation signature.
Adding new operations :
Client unaffected. Will not invoke operations it knows nothing about.
Removing operations :
An exception will occur. Messages sent by the client to the service are considered to be using an unknown action header.
Data contracts and backward compatibility
Add new non-required members :
Client unaffected. Missing values are initialized to defaults.
Add new required members :
An exception is thrown for missing values.
Remove non-required members:
Data lost at the service. Unable to return the full data set back to the client, for example. No exceptions.
Remove required members:
An exception is thrown when client receives responses from the service with missing values.
Modify existing member data types:
If types are compatible no exception but may receive unexpected results.
Related Post :
Different-option-of-hosting-wcf-service
Binding-in-wcf-choosing-right-wcf
Exchanging-metadata-in-wcf
Some-interesting-facts-about-data-contract
Knowntype-attribute-in-wcf
Associating-knowntype-in-wcf
Message-contract-in-wcf
Exception-handling-in-wcf
Exception Handling in WCF - SOAP Fault in WCF
Exception Handling in WCF - Unhandled Exception in WCF
Exception Handling in WCF - Creating and Throwing Strongly Typed SOAP Fault
I am very proud to read such an informative blog. i Will follow your updates in future so, please add more and more ideas.
ReplyDeletePython Training in Chennai
Python Classes in Chennai
Big data training in chennai
JAVA Training in Chennai
Selenium Training in Chennai
Digital Marketing Course in Chennai
Python Training in Annanagar
Thank you for giving the innovative post, Keep posting and sharing with us....!
ReplyDeleteCorporate Training in Chennai
Corporate Training institute in Chennai
Excel Training in Chennai
Embedded System Course Chennai
Oracle DBA Training in Chennai
Linux Training in Chennai
job vacancy in chennai
Power BI Training in Chennai
Corporate Training in TNagar