0

我在 Mac 和 Linux 上运行相同的 Web 应用程序。

在 Mac 上,我使用的是 Savon 0.7.6,并且网络应用程序运行良好;应用程序发起一个 SOAP 请求,如下所示:

client = Savon::Client.new("http://pvwatts.nrel.gov/PVWATTS.asmx?WSDL")

req = prep_request(@locationId, @dc_rating, @tilt, @azimuth, @derate, @array_type, @cost)

response = client.get_pvwatts{|soap| soap.input = "GetPVWATTS"; soap.body = req }
rdata = response.to_hash

这导致以下请求:

Retrieving WSDL from: http://pvwatts.nrel.gov/PVWATTS.asmx?WSDL
SOAP request: http://pvwatts.nrel.gov/PVWATTS.asmx
SOAPAction: http://pvwatts.nrel.gov/GetPVWATTS, Content-Type: text/xml;charset=UTF-8
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:wsdl="http://pvwatts.nrel.gov" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><wsdl:GetPVWATTS><wsdl:derate>0.8</wsdl:derate><wsdl:latitude>-99.0</wsdl:latitude><wsdl:pwrdgr>-0.005</wsdl:pwrdgr><wsdl:cost>0.1</wsdl:cost><wsdl:locationID>23234</wsdl:locationID><wsdl:inoct>45.0</wsdl:inoct><wsdl:mode>0</wsdl:mode><wsdl:key><key></wsdl:key><wsdl:azimuth>230</wsdl:azimuth><wsdl:tilt>20</wsdl:tilt><wsdl:DCrating>1</wsdl:DCrating><wsdl:longitude>0.0</wsdl:longitude></wsdl:GetPVWATTS></env:Body></env:Envelope>

请注意,SOAPAction 字段已填充

在 Linux 上,我使用 savon 版本 1.2.0,语法如下:

client = Savon::Client.new do
    wsdl.document = "http://pvwatts.nrel.gov/PVWATTS.asmx?WSDL"
end

req = prep_request(@locationId, @dc_rating, @tilt, @azimuth, @derate, @array_type, @cost)

response = client.request :wsdl, "GetPVWATTS" do
    soap.body = req
end

rdata response.to_hash

这会导致以下错误:

SOAP request: http://pvwatts.nrel.gov/PVWATTS.asmx
Content-Length: 750, Content-Type: text/xml;charset=UTF-8, SOAPAction: ""
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="http://pvwatts.nrel.gov" xmlns:wsdl="http://pvwatts.nrel.gov"><env:Body><ins0:GetPVWATTS><wsdl:inoct>45.0</wsdl:inoct><wsdl:tilt>20</wsdl:tilt><wsdl:cost>0.1</wsdl:cost><wsdl:locationID>23234</wsdl:locationID><wsdl:mode>0</wsdl:mode><wsdl:DCrating>1</wsdl:DCrating><wsdl:key><key></wsdl:key><wsdl:pwrdgr>-0.005</wsdl:pwrdgr><wsdl:latitude>-99.0</wsdl:latitude><wsdl:azimuth>180</wsdl:azimuth><wsdl:longitude>0.0</wsdl:longitude><wsdl:derate>0.8</wsdl:derate></ins0:GetPVWATTS></env:Body></env:Envelope>
SOAP response (status 500):
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Server did not recognize the value of HTTP Header SOAPAction: .</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>
Completed 500 Internal Server Error in 1065ms

Savon::SOAP::Fault ((soap:Client) Server did not recognize the value of HTTP Header SOAPAction: .):

请注意,未填充 SOAPAction 字段。

谁能告诉我这里有什么问题?

4

1 回答 1

0

我想出了解决方案;我的工作代码如下:

response = client.request :wsdl, "get_pvwatts" do
  soap.body = req
end

rdata = response.to_hash
于 2012-11-25T02:19:47.097 回答