使用Web服务导致“无法处理没有有效操作参数的请求”

时间:2013-10-03 15:20:22

标签: asp.net web-services soap curl fiddler

我需要在此.NET站点上使用Web服务:

https://www.iyardiasp.com/8223third_17/webservices/ItfResidentData.asmx

对于初步消费,我使用Fiddler或curl。两者都给出了同样的错误:

<faultstring>Unable to handle request without a valid action parameter. Please supply a valid soap action.</faultstring> 

我的卷曲命令:

curl -d @ GetVersionNumber.xml https://www.iyardiasp.com/8223third_17/webservices/ItfResidentData.asmx

请参阅下面的文件GetVersionNumber.xml:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
    <GetVersionNumber xmlns="http://tempuri.org/YSI.Interfaces.WebServices/ItfResidentData" />
</soap:Body>
</soap:Envelope>

添加SOAP-ENV:标题作为soap:Envelope中的元素无效

<SOAP-ENV:Header Content-Type="text/xml" Host="www.iyardiasp.com" SOAPAction="http://tempuri.org/YSI.Interfaces.WebServices/ItfResidentData/GetVersionNumber"/>

将Soap Action添加为标题无济于事。

在这种情况下,curl命令为:

curl -H“SOAPAction:http://tempuri.org/YSI.Interfaces.WebServices/ItfResidentData/GetVersionNumber” - d @ GetVersionNumber.xml“https://www.iyardiasp.com/8223third_17/webservices/itfapplicantscreening.asmx

响应是:

<faultstring>Server did not recognize the value of HTTP Header SOAPAction: http://tempuri.org/YSI.Interfaces.WebServices/ItfResidentData/GetVersionNumber.</faultstring>

1 个答案:

答案 0 :(得分:10)

您需要提供SOAPAction as a HTTP header,而不是SOAP标头。以下是使用SoapUI执行完整请求时的注意事项(请注意第四行):

POST /8223third_17/webservices/ItfResidentData.asmx HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://tempuri.org/YSI.Interfaces.WebServices/ItfResidentData/GetVersionNumber"
User-Agent: Jakarta Commons-HttpClient/3.1
Host: www.iyardiasp.com
Content-Length: 260

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:itf="http://tempuri.org/YSI.Interfaces.WebServices/ItfResidentData">
   <soapenv:Body>
      <itf:GetVersionNumber/>
   </soapenv:Body>
</soapenv:Envelope>

对于curl,您可以使用-H参数发送SOAPAction标题,但我建议您use SoapUI进行初步消费(包括SOAPAction默认情况下标题并且任何一天击败控制台。)

如果您确实需要使用curl,请尝试这样的事情(所有内容必须在一行;为了便于阅读,请将其分开):

curl -H "Content-Type: text/xml;charset=UTF-8" 
     -H "SOAPAction: \"http://tempuri.org/YSI.Interfaces.WebServices/ItfResidentData/GetVersionNumber\"" 
     -d @GetVersionNumber.xml 
     https://www.iyardiasp.com/8223third_17/webservices/ItfResidentData.asmx

GetVersionNumber.xml文件中

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:itf="http://tempuri.org/YSI.Interfaces.WebServices/ItfResidentData">
   <soapenv:Body>
      <itf:GetVersionNumber/>
   </soapenv:Body>
</soapenv:Envelope>