[英]wcf service returns “method not allowed” error
我正在嘗試將對象參數作為json格式傳遞給wcf restful service。
像這樣的服務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調用服務時,Service返回“Method not allowed”錯誤消息。
你是從瀏覽器調用服務嗎? 如果是這樣,瀏覽器使用HTTP GET請求服務,而服務方法映射到HTTP POST, Method = "POST"
,從而導致錯誤"Method not allowed"
。
要修復,如果對REST有意義或嘗試從支持POST的工具調用服務方法,請更改為Method = "GET"
,例如Fiddler或WcfTestClient
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.