我尝试使用WCF REST Contrib在.NET 3.5中设计REST服务。我的服务几乎正常,但我面临一个奇怪的错误。
基本上,我有两种方法:
[WebInvoke(UriTemplate = "/books?id={identity}", Method = "PUT")]
public string InsertBook(string identity, Book book)
{
// snipped
}
和
[WebInvoke(UriTemplate = "/books?id={identity}", Method = "GET")]
public Books[] ListBooks(string identity)
{
// snipped
}
然而,我在激活时收到错误消息:
用户代码未处理System.InvalidOperationException消息=“UriTemplateTable不支持具有与模板等同的路径的多个模板'/ books?id = {identity}'但具有不同的查询字符串,其中查询字符串不能全部消除歧义通过文字值。有关更多详细信息,请参阅UriTemplateTable的文档。“ Source =“System.ServiceModel.Web”
如果我将第二种方法重命名为/books2?identity
,那么它可以正常工作。
知道为什么UriTemplateTable
没有区分动词吗?
答案 0 :(得分:2)
终于找到了解决方案。在web.config中,绑定必须指定为webHttpBinding
(而不是默认的basicHttpBinding
)。
<system.serviceModel>
<services>
<service name="Foo.MyService">
<endpoint address="" binding="webHttpBinding" contract="Foo.MyService" />
</service>
</services>
</system.serviceModel>