WCF Contracts and Backward Compatibility

   WCF contracts are version tolerant by default. Figure 1 and Figure 2 summarize typical changes to service contracts and data contracts and describe the impact to existing clients. In short, the DataContractSerializer allows missing, non-required data and ignores superfluous data for service contracts, data contracts and similarly, message contracts. Only the removal of operations or the addition or removal of required data causes problems with existing clients.

Figure 1: Service contracts and backward compatibility

Service Contract Changes Impact to Existing Clients

Adding new parameters to an operation signature

Client unaffected. New parameters initialized to default values at the service.

Removing parameters from an operation signature

Client unaffected. Superfluous parameters pass by clients are ignored, data lost at the service.

Modifying parameter types

An exception will occur if the incoming type from the client cannot be converted to the parameter data type.

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.

Figure 2: Data contracts and backward compatibility

Data Contract Changes Impact to Existing Clients

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.


  
  3.服务契约发生变化
     3.1:向服务端方法中添加参数或者删除参数时,客户端不受影响,
     3.2:当改变参数类型后者方法返回值类型的时候,如果改变的类型,客户端不能够自动转化的话,会自动报错。
     3.3:添加一个新的方法时,客户端不受影响,因为根本就不知道新添加的方法的存在。移除一个方法时,客户端将会向服务端发送报错信息。


  4.数据契约向上兼容性
    4.1:添加一个不必要的属性成员时,客户端不受影响,初始化时,会自动添加默认值
    4.2:添加一个必要的属性成员时,将会报错
    4.3:移除一个没有必要的属性成员时,数据将会在服务端丢失,当向客户端发送请求时,不能把全部的数据发送
    4.4:更新一个属性成员的类型,如果类型是兼容的将不会报错

   

  



你可能感兴趣的:(WCF Contracts and Backward Compatibility)