开发者

IExtensibleDataObject achieving Forward and Backward compatibility

  1. I donot implement this interface in DC at Server.

  2. Though I got this implementation generated by VS2008 at client automatically, which is fine.

  3. Now i go and edit my Reference.cs to include a new field (differentiating the Server DC (inputparameter) of the particular service method)

  4. Compile, run the code pointing to old service, it works just fine though 开发者_如何学JAVAi set the value of new field (Example boolean type to true) ignoring my value.

  5. Then why should implement at server for the DC

  6. I am expecting forward compatibility and it is just working fine.

  7. Now i remove the code just i added in #3. Compile.

  8. Instead added the same field in server DC compile.

  9. Now i run the code sending lesser data from client to a server DC has more columns. It is just working fine. which means the backward compatibility is working fine?

  10. Hope some where my understanding is not correct?

My environment is .Net 3.5 Sp1


IExtensibleDataObject is for different purpose. Suppose that you have operation like:

[DataContract]
public class MyObject
{
  [DataMember]
  public string MyMember { get; set; }
}

[ServiceContract]
public class MyService
{
  [OperationContract]
  public MyObject Operation(MyObject object)
  {
    object.MyMember += " modified";
    return object;
  }
}

Expected behavior is that Operation returns modified parameter.

Now suppose that you modify data contract on the client:

[DataContract]
public class MyObject
{
  [DataMember]
  public string MyMember { get; set; }
  [DataMember]
  public string MyNewMember { get; set; }
}

Now lets call the operation:

var client = new MyServiceClient();
var myObject = new MyObject
  {
    MyMember = "Member",
    MyNewMember = "Some value"
  }; 

MyObject returnedObject = client.Operation(myObject);

The service's data contract doesn't implement IExtensibleDataObject and it doesn't know about MyNewMember property. What value will be in returnedObject.MyNewMember? It will be null. But if you implement IExtensibleDataObject on the server side it will be "Some value" even the server doesn't know anything about this property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜