【问题标题】:Rest service returns “method not allowed” on webpage休息服务在网页上返回“方法不允许”
【发布时间】:2017-02-16 14:07:15
【问题描述】:

我正在尝试将对象参数作为 JSON 格式传递给 WCF RESTful 服务。

这样的服务合约代码;

 [OperationContract]
 [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "xml/{id}")]
 string XMLData(string ID);

我的 web.config 文件是这样的;

<system.serviceModel>
<services>
  <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
    <endpoint address="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web">
    </endpoint>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

当我尝试使用“http://localhost/serviceurl/xml/123”url 调用服务时,服务返回“方法不允许”错误消息。

【问题讨论】:

    标签: c# rest wcf servicecontract


    【解决方案1】:

    我解决了。我不得不从web.config 文件中删除&lt;ProtocolMapping&gt;&lt;ServiceHostingEnvironment&gt; 标记。

    现在可以正常使用了。

    【讨论】:

      猜你喜欢
      • 2010-09-07
      • 1970-01-01
      • 2018-05-30
      • 2017-10-13
      • 2012-01-13
      • 1970-01-01
      • 2016-06-13
      • 2016-09-20
      相关资源
      最近更新 更多