我已经创建了一个WCF restful服务,它返回基本上是字符串的xml格式的组信息。为了得到这个信息,我需要传递两个参数,比如PersonId和GroupId - 都是字符串。这里一个人可以有多个小组。逻辑是,如果我同时传递PersonId和GroupId,那么它只会返回该组的具体信息,但如果我没有通过GroupId,那么方法将返回该人的所有组。到现在为止,我通过get方法使用这项服务,例如WCF Restful端点配置传递多个值
localhost/service/service.svc/getGroupInfo?PersonId=A100&GroupId=E100
or
localhost/service/service.svc/getGroupInfo?PersonId=A100&GroupId=
界面中,就像如下:
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
string getGroupInfo(string PersonId, string GroupId);
,它是给我准确的结果是什么,我的预期。然后我尝试使其成为RESTFULL并在webInvoke
中添加UriTemplate
属性。例如
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare,UriTemplate = "getGroupInfo/{PersonId}/{GroupId}")]
string getGroupInfo(string PersonId, string GroupId);
为了让我的服务问题的REST像
localhost/service/service.svc/getGroupInfo/A100/E100
而且这是工作的罚款。 但现在我的问题已经开始。如果我没有设置GroupId,它会提供服务未找到或错误的请求错误。我想选择设置groupId。 例如
对于单组
localhost/service/service.svc/getGroupInfo/A100/E100
和所有群体
localhost/service/service.svc/getGroupInfo/A100
这可能吗?
等待您的宝贵回应..
谢谢。
所有格式的检查:http://msdn.microsoft.com/en-us/library/bb675245.aspx – Luuk 2013-02-12 10:47:43