Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a SOAP request by using XML in Rails

I want to make a request to a SOAP Web Service but I don't want to install any gems. Is there any way to just make the request using plain XML?

I think it's trivial but there might be something I've missed, because all implementations/tutorials were using a gem.

I think that the SOAP response, can be handled also as a XML response right?

The request is this:

POST /services/tickets/issuer.asmx HTTP/1.1
Host: demo.demo.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <Tick xmlns="http://demo.com/test/test">
      <Request>
        <Username>string</Username>
        <Password>string</Password>
        <AcquirerId>int</AcquirerId>
        <RequestType>string</RequestType>
        <ExpirePreauth>unsignedByte</ExpirePreauth>
        <BitPerSec>int</BitPerSec>
        <Office>string</Office>
      </Request>
    </Tick>
  </soap12:Body>
</soap12:Envelope>
like image 520
Jon Romero Avatar asked Jul 26 '09 15:07

Jon Romero


People also ask

Does SOAP work with XML?

SOAP relies exclusively on XML to provide messaging services. Microsoft originally developed SOAP to take the place of older technologies that don't work well on the internet such as the Distributed Component Object Model (DCOM) and Common Object Request Broker Architecture (CORBA).

Why XML is used in SOAP?

SOAP uses XML to package the data passed to a method, or received as a response. SOAP itself is nothing more than a set of rules that define how to describe method calls and return values using XML syntax. XML merely describes data, without consideration for the way that the data is processed or presented.

What is SOAP Envelope XML?

The SOAP Envelope encapsulates all the data in a message and identifies the XML document as a SOAP message. The Header element contains additional information about the SOAP message. This information could be authentication credentials, for example, which are used by the calling application.


1 Answers

You could do this:

def post_xml(path, xml)
  host = "http://demo.demo.com"
  http = Net::HTTP.new(host)
  resp = http.post(path, xml, { 'Content-Type' => 'application/soap+xml; charset=utf-8' })
  return resp.body
end

The XML response would be returned by this method.

like image 83
Aaron Rustad Avatar answered Oct 10 '22 05:10

Aaron Rustad