2012-12-27 76 views
2

我想將對象參數作爲json格式傳遞給wcf寧靜服務。wcf服務返回「方法不允許」錯誤

這樣的服務對話代碼;

[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」 的網址,服務返回 「不允許的方法」 錯誤消息。

回答

20

你是否從瀏覽器調用服務?如果是這樣,瀏覽器使用HTTP GET請求服務,而服務方法映射到HTTP POST,Method = "POST",從而導致錯誤"Method not allowed"

要解決此問題,如果對於REST有意義,請嘗試更改爲Method = "GET",或嘗試從支持POST的工具調用服務方法,例如, FiddlerWcfTestClient

+0

感謝您的幫助,您的解決方案解決了我的問題。我用小提琴手。 – user1928388

相關問題