WCF版本控制restful方式问题
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜
service.svc/r1/GetList
是不可能的。因为您没有将ICService
继承到ICServicev1
(即公共接口 ICServicev1 : ICService
)。事实上你可以通过以下方式实现这一点。1) 使用
void GetList(int a);
方法创建ICServiceCommon
接口。2) 继承
ICServiceCommon
接口到ICService
和ICServicev1
[公共接口ICService : ICServiceCommon
和公共接口ICServicev1 : ICServiceCommon
]3) 为
MyService
类实现ICService
和ICServicev1
接口 [public class MyService : ICService, ICServicev1< /代码>]。
旧版本客户端调用相同的方法。 【向后兼容】
新的客户端可以调用
希望这个方法有用。
I guess
service.svc/r1/GetList
is not possible. Because your not inheritingICService
toICServicev1
(i.epublic interface ICServicev1 : ICService
). Infact you can achieve this with the following way.1) Create
ICServiceCommon
interface with thevoid GetList(int a);
method.2) Inherit
ICServiceCommon
interface toICService
andICServicev1
[public interface ICService : ICServiceCommon
andpublic interface ICServicev1 : ICServiceCommon
]3) Implement
ICService
andICServicev1
interfaces toMyService
class [public class MyService : ICService, ICServicev1
].The old version client call the the same methods. [backward compatibility]
and new client can call
Hope this approach is useful.