0

I am using Savon and it's working. My WSDL is:

<definitions name="demo" targetNamespace="http://localhost:8090/demo">
<message name="DemoRequest">
<part name="param1" type="xsd:string"/>
</message>
<message name="DemoResponse">
<part name="Result" type="xsd:string"/>
</message>
<portType name="DemoPortType">
<operation name="Demo">
<input message="tns:DemoRequest"/>  
<output message="tns:DemoResponse"/>
</operation>
</portType>
<binding name="DemoBinding" type="tns:DemoPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="Demo">
<soap:operation soapAction="http://localhost:8090/Demo"/>
<input>
<soap:body use="encoded" namespace="http://localhost:8090/demo" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://localhost:8090/demo"   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="DemoService">
<port name="DemoPort" binding="DemoBinding">
<soap:address location="http://localhost:8090/service.php"/>
</port>
</service>
</definitions>

My Ruby program is:

client=Savon.client(wsdl: "http://localhost:8090/demo.wsdl")
client.operations
=> [:demo]
client.call(:demo,message: {param1:"hola"}).body
=> {:demo_response=>{:result=>"Request received with param1 = hola"}}

Can I use this without Savon, something like this? the data variable is copied from the guide book I am using Pro PHP Patterns Frameworks testing and More Listing 19-2 page 289

require 'net/https'
require 'uri'
require 'nokogiri'
url = "http://localhost:8090/demo.wsdl"
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = false

# Raw SOAP XML to be passed
# TODO : Date should be dynamic
data = <<-EOF
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ns1:Demo>
    <param1 xsi:type="xsd:string">abcdefg</param1>
</ns1:Demo>
  </soap:Body>
</soap:Envelope>
EOF

# # Set Headers
# SOAPAction is mandatory
headers = {'Content-Type' => 'text/xml; charset=utf-8','SOAPAction' => "http://localhost:8090/Demo"}

result= http.post(uri.path, data, headers)

# Parse
doc = Nokogiri::XML(result.body)
doc.remove_namespaces! # Remove namespaces from xml to make it clean
p doc

The result of the variable result is something like this:

{"date":["Mon, 27 Jan 2020 16:51:03 GMT"],"server":["Apache/2.4.41 (Unix) OpenSSL/1.1.1d PHP/7.4.1 mod_perl/2.0.8-dev Perl/v5.16.3"],"last-modified":["Sun, 26 Jan 2020 21:17:35 GMT"],"etag":["\"57c-59d118504f8aa\""],"accept-ranges":["bytes"],"content-length":["1404"],"connection":["close"]} 

and the result.body variable is the same wsdl file but without any response

<?xml version ="1.0" encoding ="UTF-8" ?>
<definitions name="demo"
targetNamespace="http://localhost:8090/demo"
xmlns:tns="http://localhost:8090/demo"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="DemoRequest">
<part name="param1" type="xsd:string" />
</message>
<message name="DemoResponse">
<part name="Result" type="xsd:string" />
</message>
<portType name="DemoPortType">
<operation name="Demo">
<input message="tns:DemoRequest" />
<output message="tns:DemoResponse" />
</operation>
</portType>
<binding name="DemoBinding" type="tns:DemoPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="Demo">
<soap:operation soapAction="http://localhost:8090/Demo" />
<input>
<soap:body use="encoded" namespace="http://localhost:8090/demo"    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="http://localhost:8090/demo"    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="DemoService">
<port name="DemoPort" binding="DemoBinding">
<soap:address location="http://localhost:8090/service.php" />
</port>
</service>
</definitions>

I tried to see something like Savon:

Request received with param1 = abcdefg"

but it did not work.

  • 2
    _"can I use this without Savon"_ – absolutely, you just have to send the correct XML data as an HTTP request. The tricky part is to get the XML structure right. SOAP servers are (from my experience) very picky and will reject any malformed XML. It has to exactly match the WSDL definition. Try to inspect the HTTP request Savon makes. It shouldn't be too hard to hook into it. – Stefan Jan 27 '20 at 18:03
  • thanks i try to do that! i am new in this – Ramon Molina Jan 27 '20 at 18:06
  • show you result.body and full wsdl if you can – thiaguerd Jan 27 '20 at 21:42
  • 1
    As @Stefan says, SOAP is very picky, which is why Savon exists, to help streamline the process. Without it you're going to be responsible for a lot of lower-level things that it covers for you, and if you're new to Ruby, and especially if you're new to HTTP and XML, you're taking on a lot. I'd recommend trying to get it to work, to work with it a while, work with the Savon developers, and then consider whether you want to try a replacement if you want to do without it. – the Tin Man Jan 27 '20 at 22:47
  • Doing SOAP by hand is like making soap by hand: Tricky, fussy, and potentially dangerous. I'd trust Savon to do the right job. I would not trust my own hand-rolled code. – tadman Jan 28 '20 at 00:24
  • You can send SOAP requests with SoupUI http://www.soapui.com – Steffen Roller Jan 28 '20 at 00:59
  • @thiaguerd the complete wsdl is the one shown at the top of the page and I save it in the htdocs folder of my pc htdocs/demo.wsdl I could edit the file to show the result.body but it still doesn't show results – Ramon Molina Jan 28 '20 at 13:34

1 Answers1

0

Looks like you message is invalid.

Try send this

data = %(
  <soapenv:Envelope xmlns:demo="http://localhost:8090/demo" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header/>
    <soapenv:Body>
      <demo:Demo soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
        <param1 xsi:type="xsd:string">abcdefg</param1>
      </demo:Demo>
    </soapenv:Body>
  </soapenv:Envelope>
)
thiaguerd
  • 807
  • 1
  • 7
  • 16