【发布时间】:2009-10-06 13:17:06
【问题描述】:
我有一个自托管服务器(Windows 服务),它同时支持 SOAP/RPC(这在未来可能会消失)和 REST。 RESTful GET 按预期工作,但 PUT/POST 给出 405 错误(不支持方法)。我很确定这是我的 app.config 的配置问题,但我对此很陌生,不知道该尝试什么。
下面是我的配置文件。任何帮助都会非常感谢...
<system.serviceModel>
<!-- bindings -->
<bindings>
<basicHttpBinding>
<binding name ="soapBinding">
<security mode="None" />
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="webBinding" />
</webHttpBinding>
</bindings>
<!-- behaviors -->
<behaviors>
<endpointBehaviors>
<!-- plain old XML -->
<behavior name="poxBehavior">
<webHttp/>
</behavior>
<!-- JSON -->
<behavior name="jsonBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="DSServerBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
<!-- services -->
<services>
<service behaviorConfiguration="DSServerBehavior" name="dsServer.DSServer">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/DecisionSupportServer" />
</baseAddresses>
</host>
<endpoint address="soap"
binding="basicHttpBinding"
bindingConfiguration="soapBinding"
contract="dsServer.IDSServer" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<endpoint address="rest"
binding="webHttpBinding"
bindingConfiguration="webBinding"
behaviorConfiguration="poxBehavior"
contract="dsServer.IDSServer" />
</service>
</services>
</system.serviceModel>
【问题讨论】:
-
确认。 XML 配置已从帖子中删除。我得弄清楚如何附加它。
-
@Allan:您只需突出显示您的 XML(或代码),然后单击编辑器工具栏上的“代码”按钮 (010 101) - 或按键盘上的 Ctrl-K - 即可很好地格式化它
-
啊!感谢您修复帖子格式。
-
我会补充一点,接口使用了正确的属性,如: [WebInvoke(Method = "POST", UriTemplate = "encryptions/{plain}")] [OperationContract] String Encrypt (String普通);
-
您的服务合同上是否确实有一个属性显示 [WebInvoke(Method = "PUT"...?