gpt4 book ai didi

wcf 服务返回 "method not allowed"错误

转载 作者:行者123 更新时间:2023-12-04 16:48:41 24 4
gpt4 key购买 nike

我正在尝试将对象参数作为 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 调用服务时,服务返回“不允许的方法”错误消息。

最佳答案

您是从浏览器调用该服务吗?如果是这样,浏览器使用 HTTP GET 请求服务,而服务方法映射到 HTTP POST,Method = "POST",从而导致错误 "Method not allowed".

要解决此问题,请更改为 Method = "GET"(如果它对 REST 有意义)或尝试从支持 POST 的工具调用服务方法,例如FiddlerWcfTestClient

关于wcf 服务返回 "method not allowed"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14051246/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com