WCF版本控制restful方式问题

发布于 2024-08-29 21:23:34 字数 1303 浏览 4 评论 0原文

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

code:

[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)
   {
      ////
   }
}

这里我进行版本控制......

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

<endpoint address="" behaviorConfiguration="AjaxBehavior"
          binding="webHttpBinding" bindingConfiguration="" name="v0"
          contract="ICService" />
<endpoint address="r1" behaviorConfiguration="AjaxBehavior"
          binding="webHttpBinding" bindingConfiguration="" name="v1"
          contract="ICServicev1" />

当我调用现有方法时,它工作得很好,当我调用 service.svc/r1/GetWorkingDetails 时,它也工作得很好。但我还想调用之前合同中的 service.svc/r1/GetList 。我该如何称呼它以实现向后兼容性。

谢谢

i have two methods in Icontact and wcf service, i want to version one method for new requirement.
and want existing clients to call old code. and new client to call the new changed method and existing method for backward compatibility.

code:

[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)
   {
      ////
   }
}

here i am versioning.....

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

<endpoint address="" behaviorConfiguration="AjaxBehavior"
          binding="webHttpBinding" bindingConfiguration="" name="v0"
          contract="ICService" />
<endpoint address="r1" behaviorConfiguration="AjaxBehavior"
          binding="webHttpBinding" bindingConfiguration="" name="v1"
          contract="ICServicev1" />

When I call the existing method it works great, also when I call service.svc/r1/GetWorkingDetails it works great. But I want to also call service.svc/r1/GetList which is in previous contract. How can I call this for backward compatibility.

Thx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

行雁书 2024-09-05 21:23:34

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

1) 使用 void GetList(int a); 方法创建 ICServiceCommon 接口。

2) 继承ICServiceCommon接口到ICServiceICServicev1[公共接口ICService : ICServiceCommon公共接口ICServicev1 : ICServiceCommon]

3) 为 MyService 类实现 ICServiceICServicev1 接口 [public class MyService : ICService, ICServicev1< /代码>]。

旧版本客户端调用相同的方法。 【向后兼容】

service.svc/GetWorkingDetails
service.svc/GetList

新的客户端可以调用

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

希望这个方法有用。

I guess service.svc/r1/GetList is not possible. Because your not inheriting ICService to ICServicev1 (i.e public interface ICServicev1 : ICService). Infact you can achieve this with the following way.

1) Create ICServiceCommon interface with the void GetList(int a); method.

2) Inherit ICServiceCommon interface to ICService and ICServicev1[public interface ICService : ICServiceCommon and public interface ICServicev1 : ICServiceCommon]

3) Implement ICService and ICServicev1 interfaces to MyService class [public class MyService : ICService, ICServicev1].

The old version client call the the same methods. [backward compatibility]

service.svc/GetWorkingDetails
service.svc/GetList

and new client can call

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

Hope this approach is useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文