Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WCF版本控制restful方式问题_Wcf_Versioning_Backwards Compatibility - Fatal编程技术网

WCF版本控制restful方式问题

WCF版本控制restful方式问题,wcf,versioning,backwards-compatibility,Wcf,Versioning,Backwards Compatibility,我在Icontact和wcf服务中有两种方法,我想为新的需求版本一种方法。 并希望现有客户机调用旧代码。和新客户端调用新更改的方法和现有方法以实现向后兼容性 代码: [ServiceContract(Namespace = "http://www.testk.com/1/11", Name = "cService")] public interface ICService { [OperationContract(Name="GetWorkingDetails")] void Get

我在Icontact和wcf服务中有两种方法,我想为新的需求版本一种方法。 并希望现有客户机调用旧代码。和新客户端调用新更改的方法和现有方法以实现向后兼容性

代码:

[ServiceContract(Namespace = "http://www.testk.com/1/11", Name = "cService")]
public interface ICService
{
   [OperationContract(Name="GetWorkingDetails")]
   void GetWorkingDetails(int a);

   void GetList(int a);
}

//service Implementation
public class MyService : ICService
{
   [WebGet]
   void GetWorkingDetails(int a)
   {
     ////
   }

   [WebGet]
   void GetList(int a)
   {
      ////
   }
}
我在这里进行版本控制

调用现有方法时效果很好,调用service.svc/r1/GetWorkingDetails时效果也很好。但我还想调用service.svc/r1/GetList,它在以前的合同中。我怎样才能称之为向后兼容性

我想service.svc/r1/GetList是不可能的。因为您没有将ICService继承到ICService v1,即公共接口ICService v1:ICService。事实上,你可以通过以下方法实现这一点

1使用void GetListint a创建ICServiceCommon接口;方法

2将ICServiceCommon接口继承到ICService和ICServicev1[公共接口ICService:ICServiceCommon和公共接口ICServicev1:ICServiceCommon]

3将ICService和ICServicev1接口实现到MyService类[公共类MyService:ICService,ICServicev1]

旧版本客户端调用相同的方法。[向后兼容性]

service.svc/GetWorkingDetails
service.svc/GetList
新客户可以打电话来

service.svc/r1/GetWorkingDetailsV2
service.svc/r1/GetList
希望这种方法有用

service.svc/r1/GetWorkingDetailsV2
service.svc/r1/GetList