我在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字段。
任何人都可以告诉我这里有什么问题?
答案 0 :(得分:0)
我找到了解决方案;我的工作代码如下:
response = client.request :wsdl, "get_pvwatts" do
soap.body = req
end
rdata = response.to_hash