[OperationContract] WCF REST服务中的方法 [英] [OperationContract] Methods in WCF REST Service
本文介绍了[OperationContract] WCF REST服务中的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在[OperationContract]属性中,我编写了三种方法,例如:
In my [OperationContract] attribute I have written three methods like:
[OperationContract(Name="RolebyName")]
[WebInvoke(UriTemplate = "Role/{name}", Method = "GET", RequestFormat =WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,BodyStyle = WebMessageBodyStyle.Bare)]
Role1 GetRole(string name);
[OperationContract(Name="RolebyProviderId")]
[WebInvoke(UriTemplate = "Rolebypid/?pid={providerId}", Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
Role1 GetRolebyId(Guid providerId);
[OperationContract(Name="RolebyCompanyProviderId")]
[WebInvoke(UriTemplate = "RolebyCPid/?companyId={companyId}&providerId={providerId}", Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
Role1 GetRolebyCPId(Guid companyId, Guid providerId);
我将在Service.cs类中分别实现这三种方法
我的问题是...我不能单独实现三个方法,而不能实现一个类并隐含其中的方法?
如果是这样,如何在[OperationContract]中声明该类并在Service.cs中实现它;基于传递的参数,它必须调用该特定方法?
I am implementing these three methods separately in Service.cs class
My question is... Instead of implementing as three methods separately can I implement a single class and implemnt the methods inside it ?
If so how can I declare the class in [OperationContract] and also implement it in Service.cs;Based on the parameter passed it has to call that particular method ?
推荐答案
很抱歉,但我没有看到一个单独的示例可以按照您想要的方式完成.认为您必须像现在那样按方法实现它们:)
Im sorry but I have not seen a single example were this is done in the way you want. Think they would have to be implemented per method as you have done now :)
这篇关于[OperationContract] WCF REST服务中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文