2

オブジェクトパラメータを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://localhost/serviceurl/PR」URL でサービスを呼び出そうとすると、サービスは「メソッドは許可されていません」というエラー メッセージを返しました。

4

1 に答える 1

21

ブラウザからサービスを呼び出していますか? その場合、ブラウザは HTTP GET を使用してサービスをリクエストしますが、サービス メソッドは HTTP POST にマップされるためMethod = "POST"、エラーが発生します"Method not allowed"

修正するにMethod = "GET"は、REST に関して意味がある場合に変更するか、POST をサポートするツール ( FiddlerWcfTestClientなど) からサービス メソッドを呼び出してみてください。

于 2012-12-27T08:31:03.723 に答える