开发者

WCF Versioning restful way problem

开发者 https://www.devze.com 2022-12-27 12:10 出处:网络
i have two methods inIcontact 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

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
{
    [OperationC开发者_StackOverflowontract(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


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.

0

精彩评论

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