我正在尝试将对象参数作为 json 格式传递给 wcf Restful 服务。
像这样的服务合约代码;
[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 调用服务时,服务返回“不允许方法”错误消息。
您是从浏览器调用该服务吗?如果是这样,浏览器使用 HTTP GET 请求服务,同时服务方法映射到 HTTP POST,Method = "POST"
,从而导致错误"Method not allowed"
.
要修复,请更改为Method = "GET"
如果对于 REST 有意义,或者尝试从支持 POST 的工具调用服务方法,例如Fiddler http://www.fiddler2.com/fiddler2/ or Wcf测试客户端 http://msdn.microsoft.com/en-us/library/bb552364.aspx
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)