SOAP with Ruby
This is raw HTML, inside Markdown.
I guess it’s so rare case to use SOAP nowadays. But sometimes we must do it. If we call SOAP with curl, we can use it as the following. Request.xml is for the request header and body.curl https://hogehoge -H 'Content-Type: text/xml;charset=UTF-8' -H 'Accept-Charset: utf-8' \-d @request.xml
For Ruby, we can use savon as the SOAP Gem.
require 'savon'
xml = <<'EOS'
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
(略)
</soapenv:Body>
</soapenv:Envelope>
EOS
client = Savon.client(
:wsdl => 'https://hogehoge?wsdl',
)
puts client.operations
response = client.call(:fuga, xml: xml)
p response.body
if we run client.operations
, then you can see the list of the method we can use. fuga
is the method in the above sample. You can write xml
directly or you can specify the path like this. client.call(:fuga, xml: './request.xml')
comments powered by Disqus