WCF服务返回“方法不被允许”的错误(wcf service returns “method not

2019-08-04 18:33发布

我试图通过对象参数为JSON格式WCF RESTful服务。

服务conratc这样的代码;

[WebInvoke(
    Method = "POST",
    BodyStyle = WebMessageBodyStyle.Wrapped,
    ResponseFormat = WebMessageFormat.Json,
    RequestFormat = WebMessageFormat.Json,
    UriTemplate="PR")]
[OperationContract]
TWorkRequestPostResult PostRequest(TWorkRequestPostArgs args);

而我的web.config文件这样;

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="WebDAVModule"/>
    </modules>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true" />
  </system.webServer>  

当我试图与调用服务的“http://本地主机/ serviceURL中/ PR”的网址,服务返回“不允许的方法”错误消息。

Answer 1:

你叫来自浏览器的服务? 如果是这样,而服务方法被映射到HTTP POST,浏览器请求使用HTTP GET服务Method = "POST" ,从而导致错误"Method not allowed"

要解决,要么改变Method = "GET"是否有意义有关于REST或尝试从支持POST,例如工具调用服务方法提琴手或WcfTestClient



文章来源: wcf service returns “method not allowed” error
标签: wcf rest