开发者

UriTemplateTable not distinguishing verbs

开发者 https://www.devze.com 2022-12-28 11:50 出处:网络
I have trying to design a REST service in .NET 3.5 with WCF REST Contrib. My service is nearly working fine, but I am facing a bizarre error.

I have trying to design a REST service in .NET 3.5 with WCF REST Contrib. My service is nearly working fine, but I am facing a bizarre error.

Basically, I have two methods:

[WebInvoke(UriTemplate = "/books?id={identity}", Method = "PUT")]
public string InsertBook(string identity, Book book)
{
 // snipped
}

and

[WebInvoke(UriTemplate = "/books?id={identity}", Method = "GET")]
public Books[] ListBooks(string identity)
{
 // snipped
}

Yet I am getting the error message at activation time:

System.InvalidOperationException was unhandled by user code Message="UriTemplateTable does not support multiple templates that have equivalent path as template '/books?id={identity}' but have diffe开发者_高级运维rent query strings, where the query strings cannot all be disambiguated via literal values. See the documentation for UriTemplateTable for more detail." Source="System.ServiceModel.Web"

If I rename the second method as /books2?identity then it works fine.

Any idea why the UriTemplateTable is not distinguishing between verbs?


Finally found the solution. In the web.config, the binding must be specified as webHttpBinding (instead of the default basicHttpBinding).

<system.serviceModel>
  <services>
    <service name="Foo.MyService">
      <endpoint address="" binding="webHttpBinding" contract="Foo.MyService" />
    </service>
  </services>
</system.serviceModel>
0

精彩评论

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