I am currently working on a ROR project that needs to consume some SOAP based web services. What I know about consuming web services borders on the 'dangerous'. The example that the site provides is using asp with XMLHTTP to send what appears to be some XML wrapped in a SOAP envelope. Included in the XML is the authentication information as well. If I build the XML separately could I then use HTTParty to send it on and get back the response?
If HTTParty is not the answer then any alternative suggestions would be very useful. Below is the asp example provided.
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/webserv开发者_运维百科ices/"">"
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
It's possible to use HTTParty or any other HTTP client, but I wouldn't recommend it. You'd have to manually construct and deconstruct SOAP envelopes and objects.
Instead, try the Savon library. Although fairly new, it seems to be the module of choice for SOAP, over the venerable soap4r.
精彩评论