views:

494

answers:

2

I was curious if someone could outline which types of WCF contract (interface) changes on the server side would break a client trying to send in a message, and why. I believe WCF can handle certain discrepancies, but I'm not sure exactly what you can change safely, and what you can't.

  • Add/remove parameters from an OperationContract?
  • Add/remove/change the DataContract's serialized properties?
  • Add/remove OperationContracts from a ServiceContract?

A friend asked a similar question here:

http://stackoverflow.com/questions/631935/does-adding-a-method-to-a-wcf-servicecontract-break-existing-clients

EDIT: As John Saunders pointed out, changing the contract is not usually a good idea, but there are things built in that allow for some version tolerance (ExtensionDataObject, etc.?). I would just like to know how flexible the version tolerance is.

+1  A: 

I think the best practice is to think of contracts as unbreakable, hmmm, contracts. Don't change them once they're published. It's easy enough to create a new contract with the changes you want, and to expose the new contract on a new endpoint.

John Saunders
I agree with the overall concept of not changing contracts, but if you make small changes to a contract, I don't know if it's always a good idea to publish a new endpoint for every new contract. Any thoughts on this?
Andy White
My thought is, "give 'em an inch, and they'll take a mile". Don't get into the habit of allowing "small" changes, or they'll make big ones.
John Saunders
+5  A: 

Check out this article on dasBlonde Versioning WCF Service Contracts.

It lists what changes will break existing clients:

    Remove operations
    Change operation name
    Remove operation parameters
    Add operation parameters
    Change an operation parameter name or data type
    Change an operation's return value type
    Change the serialized XML format for a parameter type (data contract) or operation (message contract) by explicitly using .NET attributes or custom serialization code
    Modify service operation encoding formats (RPC Encoding vs. Document Literal)

This article by Michele explains in more detail how you can design contracts to be more flexible.

Design Services Contracts with WCF

Jonathan Parker
Thanks, that's exactly what I was looking for
Andy White