wcf 服务不允许 POST
Posted
技术标签:
【中文标题】wcf 服务不允许 POST【英文标题】:wcf service doesn't allow POST 【发布时间】:2012-06-11 10:39:52 【问题描述】:一般来说,我对 webervices 还是很陌生,并且陷入了(我认为)配置 IIS 和 web 服务本身的困境。
我在 MVS 2010 中创建了一个 wcf 网络服务,并将其托管在 Windows 7 上的 IIS7.5 上。 我使用soapUI 4.5.0 发布一条消息,该消息由我创建webservice 合同时使用的相同wsdl 描述生成。问题是我得到 405,因为 web 服务或 web 服务器似乎不支持 http POST。
尽管我知道我得到的错误足以解决我的问题,但我对 IIS 和 Web 服务的了解不足,使我无法找到正确的解决方案。
低于我能想到的尽可能多的信息。希望它有任何帮助,有人可以指导我正确的方向。
在 IIS 中进行的配置:
授权规则:允许,所有用户
目录浏览:启用 处理程序映射:功能权限:读取、脚本和执行 处理程序映射:添加 *.wsdl -> ProtocolSupportModule -> GET、HEAD、OPTIONS、TRACE、POST 应用程序池:添加了具有身份 NetworkService 的条目,使用 .net fw 4.0这是发送的消息:
原始: POST http:x.x.x.x:21378/HTTP/1.1 接受编码:gzip,deflate 内容类型:application/soap+xml;charset=UTF-8;action="/BootNotification"
XML:
<soap:Envelope xmlns:soap="org/2003/05/soap-envelope" xmlns:ns="urn://Ocpp/Cs/2012/02/">
<soap:Header/>
<soap:Body>
<ns:bootNotificationResponse>
<ns:status>Accepted</ns:status>
<ns:currentTime>$now</ns:currentTime>
<ns:heartbeatInterval>900</ns:heartbeatInterval>
</ns:bootNotificationResponse>
</soap:Body>
</soap:Envelope>
这是返回的结果:
我截断了它以限制这篇文章的大小。
原始: HTTP/1.1 405 方法不允许 缓存控制:私有 允许:GET、HEAD、OPTIONS、TRACE 内容类型:文本/html;字符集=utf-8 服务器:Microsoft-IIS/7.5 X-Powered-By: ASP.NET 日期:2012 年 6 月 7 日星期四 07:58:09 GMT 内容长度:5611
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns=".org/1999/xhtml">
<head>
<title>IIS 7.5 Detailed Error - 405.0 - Method Not Allowed</title>
<style type="text/css">
...
...
...
<div class="content-container">
<fieldset><legend>Most likely causes:</legend>
<ul> <li>The request sent to the Web server used an HTTP verb that is not allowed by the module configured to handle the request.</li> <li>A request was sent to the server that contained an invalid HTTP verb.</li> <li>The request is for static content and contains an HTTP verb other than GET or HEAD.</li> <li>A request was sent to a virtual directory using the HTTP verb POST and the default document is a static file that does not support HTTP verbs other than GET or HEAD.</li> </ul>
</fieldset>
</div>
<div class="content-container">
<fieldset><legend>Things you can try:</legend>
<ul> <li>Verify the list of verbs enabled for the module handler this request was sent to, and ensure that this verb should be allowed for the Web site.</li> <li>Check the IIS log file to see which verb is not allowed for the request.</li> <li>Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click <a href=".com/fwlink/?LinkID=66439">here</a>. </li> </ul>
</fieldset>
</div>
<div class="content-container">
<fieldset><legend>Links and More Information</legend>
This error means that the request sent to the Web server contained an HTTP verb that is not allowed by the configured module handler for the request.
<p><a href="amp;IIS70Error=405,0,0x80070001,7601">View more information »</a></p>
</fieldset>
</div>
</div>
</body>
</html>
XML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ".org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns=".org/1999/xhtml">
<head>
<title>IIS 7.5 Detailed Error - 405.0 - Method Not Allowed</title>
<style type="text/css">
...
</head>
<body>
<div id="header"><h1>Server Error in Application "SHENZIWEBSERVICEDEPLOYED"</h1></div>
<div id="server_version"><p>Internet Information Services 7.5</p></div>
<div id="content">
<div class="content-container">
<fieldset><legend>Error Summary</legend>
<h2>HTTP Error 405.0 - Method Not Allowed</h2>
<h3>The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.</h3>
</fieldset>
</div>
<div class="content-container">
...
</div>
<div class="content-container">
<fieldset><legend>Most likely causes:</legend>
<ul> <li>The request sent to the Web server used an HTTP verb that is not allowed by the module configured to handle the request.</li> <li>A request was sent to the server that contained an invalid HTTP verb.</li> <li>The request is for static content and contains an HTTP verb other than GET or HEAD.</li> <li>A request was sent to a virtual directory using the HTTP verb POST and the default document is a static file that does not support HTTP verbs other than GET or HEAD.</li> </ul>
</fieldset>
</div>
<div class="content-container">
<fieldset><legend>Things you can try:</legend>
<ul> <li>Verify the list of verbs enabled for the module handler this request was sent to, and ensure that this verb should be allowed for the Web site.</li> <li>Check the IIS log file to see which verb is not allowed for the request.</li> <li>Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click <a href=".com/fwlink/?LinkID=66439">here</a>. </li> </ul>
</fieldset>
</div>
<div class="content-container">
<fieldset><legend>Links and More Information</legend>
This error means that the request sent to the Web server contained an HTTP verb that is not allowed by the configured module handler for the request.
<p><a href=".com/fwlink/?LinkID=62293&IIS70Error=405,0,0x80070001,7601">View more information »</a></p>
</fieldset>
</div>
</div>
</body>
</html>
这是生成的服务合同的一部分(wsdl /language:CS /serverInterface
// CODEGEN: The optional WSDL extension element 'PolicyReference' from namespace 'http://schemas.xmlsoap.org/ws/2004/09/policy' was not handled.
[ServiceContract(Name = "CentralSystemServiceSoap", Namespace = "urn://Ocpp/Cs/2010/08/")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.Web.Services.WebServiceBindingAttribute(Name="CentralSystemServiceSoap", Namespace="urn://Ocpp/Cs/2010/08/")]
public interface ICentralSystemServiceSoap
/// <remarks/>
[OperationContract]
[System.Web.Services.Protocols.SoapHeaderAttribute("chargeBoxIdentity")]
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("/BootNotification", RequestElementName = "bootNotificationRequest", RequestNamespace = "urn://Ocpp/Cs/2010/08/", ResponseElementName = "bootNotificationResponse", ResponseNamespace = "urn://Ocpp/Cs/2010/08/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("status")]
RegistrationStatus BootNotification(string chargePointVendor, string chargePointModel, string chargePointSerialNumber, string chargeBoxSerialNumber, string firmwareVersion, string iccid, string imsi, string meterType, string meterSerialNumber, out System.DateTime currentTime, [System.Xml.Serialization.XmlIgnoreAttribute()] out bool currentTimeSpecified, out int heartbeatInterval, [System.Xml.Serialization.XmlIgnoreAttribute()] out bool heartbeatIntervalSpecified);
【问题讨论】:
【参考方案1】:我不了解您的服务是如何构建的以及您在那里做了什么,但根据我的经验,这是创建支持 POST 请求的 wcf RESTful 服务的简单方法:
http://www.codeproject.com/Articles/201901/CREATE-RESTful-WCF-Service-API-Using-POST-Step-By
根据 cmets 更新:
尝试使用它:
[OperationContract]
[WebInvoke(Method = "POST")]
[System.Web.Services.Protocols.SoapHeaderAttribute("chargeBoxIdentity")]
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("/BootNotification", RequestElementName = "bootNotificationRequest", RequestNamespace = "urn://Ocpp/Cs/2010/08/", ResponseElementName = "bootNotificationResponse", ResponseNamespace = "urn://Ocpp/Cs/2010/08/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("status")]
RegistrationStatus BootNotification(string chargePointVendor, string chargePointModel, string chargePointSerialNumber, string chargeBoxSerialNumber, string firmwareVersion, string iccid, string imsi, string meterType, string meterSerialNumber, out System.DateTime currentTime, [System.Xml.Serialization.XmlIgnoreAttribute()] out bool currentTimeSpecified, out int heartbeatInterval, [System.Xml.Serialization.XmlIgnoreAttribute()] out bool heartbeatIntervalSpecified);
更新
尝试这样做:
在 IIS 7.5 上 -> YourWebsite -> 处理程序映射
选择面板右侧的“添加模块映射”选项
在“请求路径”字段中输入 *.wsdl
在“模块”字段中输入“ProtocolSupportModule”
点击“请求限制”并转到动词选项卡
输入 POST 动词
保存更改
【讨论】:
感谢您的快速响应。该链接很有帮助,我以前看过,但无法将其链接到我的问题。我会更仔细地研究它。我在帖子中添加了部分生成的合同。 我不确定,但请尝试在 [OperationContract] 属性下添加 '[WebInvoke(Method = "POST")]' 属性 我会尝试并整理出 webhttpbinding ict wshttpbinding 和 basichttpbinding。不知道具体的区别是什么。 我添加了属性,但对结果没有影响。响应仍然只告诉我:允许:GET、HEAD、OPTIONS、TRACE 是允许的。我也有这样的想法,不是网络服务在回复这个,而是网络服务器。这可能吗?网络服务器不让网络服务处理帖子,而是将其过滤掉? 我确实在处理程序映射中配置了 *.wsdl。以上是关于wcf 服务不允许 POST的主要内容,如果未能解决你的问题,请参考以下文章
WCF RESTful 应用程序 PUT、POST、DELETE 收到相同的错误:“该方法不允许。”
在带有 Wcf 服务的 Angular JS 的预检响应中,Access-Control-Allow-Methods 不允许方法 PUT