我正在尝试将对象参数作为json格式传递给wcf restful service.
像这样的服务conratc代码;
[WebInvoke(
Method = "POST",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
UriTemplate="PR")]
[OperationContract]
TWorkRequestPostResult PostRequest(TWorkRequestPostArgs args);
Run Code Online (Sandbox Code Playgroud)
和我的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>
Run Code Online (Sandbox Code Playgroud)
当我尝试使用"http:// localhost/serviceurl/PR"url调用服务时,Service返回"Method not allowed"错误消息.
Mar*_*sen 20
你是从浏览器调用服务吗?如果是这样,浏览器使用HTTP GET请求服务,而服务方法映射到HTTP POST Method = "POST",从而导致错误"Method not allowed".
要修复,要么改为对Method = "GET"REST有意义,要么尝试从支持POST的工具调用服务方法,例如Fiddler或WcfTestClient
| 归档时间: |
|
| 查看次数: |
26013 次 |
| 最近记录: |