我可以使用httparty或厌倦消费SOAP Web服务吗?

时间:2010-10-29 11:46:36

标签: ruby-on-rails soap httparty

我目前正在开发一个需要使用一些基于SOAP的Web服务的ROR项目。我对消费Web服务的了解与“危险”有关。该站点提供的示例是使用带有XMLHTTP的asp来发送看似包含在SOAP信封中的XML。 XML中还包括身份验证信息。如果我单独构建XML,那么我可以使用HTTParty发送它并获取响应吗?

如果HTTParty不是答案,那么任何替代建议都会非常有用。下面是提供的asp示例。

const SoapServer = "http://demo.touricoholidays.com/ws/HotelsService.asmx"
set xmldom = server.CreateObject("Microsoft.XMLDOM")
set xmlhttp = server.CreateObject("Microsoft.XMLHTTP")


xmlhttp.open "POST", SoapServer, false
xmlhttp.setRequestHeader "Content-Type", "text/xml"
xmlhttp.setRequestHeader "SOAPAction", "http://tourico.com/webservices/GetHotelDetails"
xmlhttp.send(SoapTest)

if xmlhttp.Status = 200 then '405 means error, 200 means ok. You know why.

Set xmldom = xmlhttp.responseXML
Response.write(xmldom.xml)

Else
Response.Write("Didn't Work<BR>")
 Response.Write("status="&xmlhttp.status)
 Response.write("<BR>"&xmlhttp.statusText)
 Response.Write("<BR>"&Request.ServerVariables("ALL_HTTP"))
End if
set xmlhttp = nothing
set xmldom = nothing
function SoapTest()
SoapTest = SoapTest & "<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:SOAP-ENC=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:m0=""http://example.com/travelservices/""> "
SoapTest = SoapTest & "<SOAP-ENV:Header>"
SoapTest = SoapTest & "<m:LoginHeader xmlns:m=""http://example.com/webservices/"">"
SoapTest = SoapTest & "<m0:username>ABC</m0:username> "
SoapTest = SoapTest & "<m0:password>123</m0:password> "
SoapTest = SoapTest & "</m:LoginHeader>"
SoapTest = SoapTest & "</SOAP-ENV:Header>"
SoapTest = SoapTest & "<SOAP-ENV:Body>"
SoapTest = SoapTest & "<m:GetHotelDetails xmlns:m=""http://example.com/webservices/"">"
SoapTest = SoapTest & "<m:HotelID>2205</m:HotelID> "
SoapTest = SoapTest & "<m:provider>localTgsProvider</m:provider> "
SoapTest = SoapTest & "</m:GetHotelDetails>"
SoapTest = SoapTest & "</SOAP-ENV:Body>"
SoapTest = SoapTest & "</SOAP-ENV:Envelope>"
end function

1 个答案:

答案 0 :(得分:3)

可能使用HTTParty或任何其他HTTP客户端,但我不推荐它。您必须手动构造和解构SOAP信封和对象。

相反,请尝试使用Savon库。虽然相当新,但它似乎是SOAP的首选模块,而不是古老的soap4r。