简体   繁体   English

wcf服务不允许POST

[英]wcf service doesn't allow POST

I'm quite new to webervices in general and am getting stuck in (I think) configuring IIS and the webservice itself. 一般而言,我对Webervices还是很陌生,并且陷入(我认为)配置IIS和Webservice本身的问题。

I created a wcf webservice in MVS 2010 and hosted it on IIS7.5 on windows 7. I use soapUI 4.5.0 to post a message generated from the same wsdl description I created the webservice contract with. 我在MVS 2010中创建了一个wcf Web服务,并将其托管在Windows 7的IIS7.5上。我使用soapUI 4.5.0来发布一条消息,该消息是从与创建Webservice合同相同的wsdl描述生成的。 Issue is that I get 405 due to the fact that http POST not seems to be supported by the webservice or webserver. 问题是由于网络服务或网络服务器似乎不支持http POST,所以我得到405。

Even though I had the idea the error I get would be sufficient to solve my problem, my lack of knowledge about IIS and webservices makes I can't find the right solution. 即使我有一个错误提示,也足以解决我的问题,但是由于我对IIS和Web服务的了解不足,所以我找不到正确的解决方案。

Below as much information as I could think of. 下面是我能想到的尽可能多的信息。 Hope it is of any help and someone can guide me in the right direction. 希望对您有所帮助,有人可以指导我朝正确的方向发展。

Configurations made in IIS: 在IIS中进行的配置:

Authorization rule: allow, all users 授权规则:允许,所有用户

  • Directory browsing: enabled 目录浏览:已启用
  • Handler mappings: features permissions: read, script and execute 处理程序映射:功能许可:读取,脚本和执行
  • Handler mappings: added *.wsdl -> ProtocolSupportModule -> GET, HEAD, OPTIONS, TRACE, POST 处理程序映射:添加* .wsdl-> ProtocolSupportModule-> GET,HEAD,OPTIONS,TRACE,POST
  • Application pools: added entry with identity NetworkService using .net fw 4.0 应用程序池:使用.net fw 4.0添加了具有标识NetworkService的条目

This is the message sent: 这是发送的消息:

RAW: POST http: xxxx:21378/ HTTP/1.1 Accept-Encoding: gzip,deflate Content-Type: application/soap+xml;charset=UTF-8;action="/BootNotification" RAW:POST http:xxxx:21378 / HTTP / 1.1接受编码:gzip,压缩内容类型:application / soap + xml; charset = UTF-8; action =“ / BootNotification”

XML: 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>

This is the result returned: 这是返回的结果:

I truncated it to limit the size of this post. 我将其截断以限制此帖子的大小。

RAW: HTTP/1.1 405 Method Not Allowed Cache-Control: private Allow: GET, HEAD, OPTIONS, TRACE Content-Type: text/html; RAW:HTTP / 1.1 405不允许的方法高速缓存控制:专用允许:GET,HEAD,OPTIONS,TRACE内容类型:text / html; charset=utf-8 Server: Microsoft-IIS/7.5 X-Powered-By: ASP.NET Date: Thu, 07 Jun 2012 07:58:09 GMT Content-Length: 5611 charset = utf-8服务器:Microsoft-IIS / 7.5 X-Powered-通过: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 &raquo;</a></p> 

 </fieldset> 
</div> 
</div> 
</body> 
</html> 

XML: 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&amp;IIS70Error=405,0,0x80070001,7601">View more information &raquo;</a></p> 

 </fieldset> 
</div> 
</div> 
</body> 
</html> 

This is part of the generated servicecontract (wsdl /language:CS /serverInterface 这是生成的服务合同的一部分(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);

I didn't understand how your service is built and what you have done there, but from my experience, this is a simple way to create a wcf RESTful service that supports POST requests: 我不了解您的服务是如何构建的以及您在那做的事情,但是根据我的经验,这是创建支持POST请求的wcf RESTful服务的简单方法:

http://www.codeproject.com/Articles/201901/CREATE-RESTful-WCF-Service-API-Using-POST-Step-By http://www.codeproject.com/Articles/201901/CREATE-RESTful-WCF-Service-API-Using-POST-Step-By

Update according to the comments: 根据评论更新:

try using that: 尝试使用:

[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);

UPDATE 更新

try doing that: 尝试这样做:

On IIS 7.5 -> YourWebsite -> Handler Mappings 在IIS 7.5-> YourWebsite->处理程序映射上

Choose "Add module mapping" option on the right side of the panel 选择面板右侧的“添加模块映射”选项

In "Request path" field enter *.wsdl 在“请求路径”字段中输入* .wsdl

In "Module" field enter "ProtocolSupportModule" 在“模块”字段中输入“ ProtocolSupportModule”

Click on "Request restrictions" and go to Verbs tab 点击“请求限制”,然后转到动词标签

Enter POST verb 输入POST动词

Save changes 保存更改

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM