Ruby Savon: Call SOAP webservice without operation - ruby

I need to call a SOAP service that doesn’t contain any operation encapsulation on the body.
Normally with Savon (Ruby 2.3, Savon 2.11) we have:
client = Savon.client(endpoint: 'http://example.com', namespace: 'http://v1.example.com')
response = client.call(:opName, message_hash)
And this will generate a request like:
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsdl="http://v1.example.com" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<wsdl:opName>
...message content ...
</wsdl:opName>
</env:Body>
</env:Envelope>
But I dont want it to generate the <wsdl:opName> node. I tried to passnil as the operation but it generates the tag as <wsdl:>.
I want to generate a SOAP request without it, like:
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsdl="http://v1.example.com" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
...message content ...
</env:Body>
</env:Envelope>

Related

How to force Savon to use a specific parameter case

I"m trying to connect to a SOAP API using Savon.
The WSDL shows this:
wsdl:operation name="CustomerList" parameterOrder="Username Password Settings">
<wsdl:input message="impl:CustomerListRequest" name="CustomerListRequest"/>
<wsdl:output message="impl:CustomerListResponse" name="CustomerListResponse"/>
</wsdl:operation>
Customer Support says to use a request such as this:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ei2="http://ei2.nobj.nable.com/">
<soap:Header/>
<soap:Body>
<ei2:customerList>
<!--Optional:-->
<ei2:username>testaccount#n-able.com</ei2:username>
<!--Optional:-->
<ei2:password>!PDf2lfij23l!!</ei2:password>
<!--Zero or more repetitions:-->
<ei2:settings>
<!--Optional:-->
<ei2:key>null</ei2:key>
<!--Optional:-->
<ei2:value>null</ei2:value>
</ei2:settings>
</ei2:customerList>
</soap:Body>
</soap:Envelope>
This is my request:
{"SOAPAction"=>"\"CustomerList\"", "Content-Type"=>"text/xml;charset=UTF-8", "Content-Length"=>"452"}
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:impl="http://www.n-able.com/mickey" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<impl:CustomerList>
<username>test#test.com</username>
<password>MytestPassword1234</password>
<settings>
<listSOs>false</listSOs>
</settings>
</impl:CustomerList>
</env:Body>
</env:Envelope>
The difference is that the WSDL which Savon consumes and generates methods to call off of, is making my request send CustomerList instead of the customerList the API seems to be expecting.
Is there a way to force Savon to send CustomerList instead of customerList without constructing the entire SOAP Request by hand?
Edit 1
Found the answer in this Github Issue. https://github.com/savonrb/savon/issues/530
By adding the following to a gemspec, I was able to get a well formed request:
spec.add_runtime_dependency 'savon', '~> 2.3'
spec.add_runtime_dependency 'wasabi', '~> 3.2'
include one of those when you build your client:
convert_request_keys_to :camelcase # or one of [:lower_camelcase, :upcase, :none]
or work without the WSDL and hand code the call with 'strings'.

How send Soap custom message using ruby savon client

I need send message request in Ruby.This message works in the SoapUI see example below:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body><auth:callAuth xmlns:auth="http://auth.org"><auth:StringInput><?xml version="1.0" encoding="UTF-8" ?><ns0:TestService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://xml.netbeans.org/schema/TestService" xsi:schemaLocation="http://xml.netbeans.org/schema/TestService AuthReqType.xsd http://xml.netbeans.org/schema/TestService HeaderType.xsd http://xml.netbeans.org/schema/TestService AuthResType.xsd http://xml.netbeans.org/schema/TestService TestService.xsd"><ns0:Header><ns0:Version>3.4.2</ns0:Version><ns0:SrcApp>Test</ns0:SrcApp><ns0:TargetApp>AppName</ns0:TargetApp><ns0:SrcMsgId>00000001198469411500</ns0:SrcMsgId><ns0:TranTimeStamp>20130329104502</ns0:TranTimeStamp></ns0:Header><ns0:Body><ns0:AuthReq><ns0:MsgType>0200</ns0:MsgType><ns0:RvslCde>00</ns0:RvslCde></ns0:AuthReq></ns0:Body></ns0:TestService> ]]></auth:StringInput></auth:callAuth></soapenv:Body>

Ruby's soap4r not providing namespace?

I'm attempting to use soap4r (from https://github.com/mumboe/soap4r) to write a SOAP Client for a product called SysAid.
I have a working example of the SOAP client in Java and, for most methods, my Ruby client works too. The Java client is useful in determining errors with the Ruby version.
I'm receiving an error when I use a particular call:
SOAP::FaultError: prefix xs is not bound to a namespace
Here's the message that soap4r sent, which generated that error:
<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<n1:save xmlns:n1="http://api.ilient.com/">
<sessionId>1339292997261</sessionId>
<apiSysObj xsi:type="n1:apiServiceRequest">
<customDateFields></customDateFields>
<customFields>
<entry>
<key xsi:type="xs:string">sr_cust_dafis_fau</key>
<value xsi:type="xs:string"></value>
</entry>
<entry>
<key xsi:type="xs:string">sr_cust_activity</key>
</entry>
</customFields>
<description>This is the description of the ticket.</description>
</apiSysObj>
</n1:save>
</env:Body>
</env:Envelope>
And here is what Java sends for the same method, which the server does not complain about:
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:save xmlns:ns2="http://api.ilient.com/">
<sessionId>1339199684324</sessionId>
<apiSysObj xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:apiServiceRequest">
<customDateFields/><customFields>
<entry>
<key xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">sr_cust_dafis_fau</key>
<value xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"></value>
</entry>
<entry>
<key xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">sr_cust_activity</key>
</entry>
</customFields>
<description>This is the description of the ticket.</description>
</apiSysObj>
</ns2:save>
</S:Body>
</S:Envelope>
As you can see, the error is coming from the customFields tag. soap4r is leaving out the xmlns:xs attribute on the key tag, while Java is putting it in.
soap4r does not make critical errors like this on any other method call as far as I can tell.
How can I get soap4r to add this needed attribute to the key tag?
I think the namespace "xmlns:xsd="http://www.w3.org/2001/XMLSchema" has been defined in the "env:Envelope", the problem is why in the body soap4r uses "xs:string" instead of "xsd:string".

Savon ruby gem adds ins0 to tags

Using the savon gem, I get the following request XML:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsdl="URL"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ins0="SOME URL">
<soap:Body>
<ins0:Test xmlns="SOME URL">
</ins0:Test>
</soap:Body>
</soap:Envelope>
But it needs to be this instead:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsdl="URL"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Test xmlns="SOME URL">
</Test>
</soap:Body>
</soap:Envelope>
Notice ins0 was removed.
Any suggestions?
The two XML documents are equivalent, so there should be no issues as long as the document is parsed by an XML compliant agent.
The Savon generated document is simply creating a namespace prefix of ins0 for the "SOME URL" namespace. This is convenient for a large SOAP document with many elements from that namespace. In this example, the prefix is not really necessary.
The only potential issue I can see is that the Savion generated document seems to declare the ins0 namespace twice - once in the soap:Envelope and then again in the soap:Body. Seems superfluous and potentially open to error.

CleverElements / Sendcockpit SOAP API parameters aren't recognized

I'm trying to use the CleverElements SOAP API, but I can't get it to work. I have honestly never worked with SOAP (but a lot with XML-RPC, REST, etc.), and thought it should be straightforward.
I'm using Ruby with the savon gem. I can call any function via SOAP which doesn't need any parameters, but on functions with parameters, the SOAP service doesn't recognize the parameters.
This is my request:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="Sendcockpit/API" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="Sendcockpit/API">
<env:Header>
<validate>
<userid>32027</userid>
<apikey>**************</apikey>
<version>1.0</version>
<mode>live</mode>
</validate>
</env:Header>
<env:Body>
<apiGetListDetails>
<listID>72472</listID>
</apiGetListDetails>
</env:Body>
</env:Envelope>
This is the WSDL file: http://api.sendcockpit.com/server.php?wsdl
Am I missing something (maybe dead simple, super obvious, basic SOAP) stuff?
Never mind. Apparently I need a wrapping <ctListRequest> node. I was under the impression that savon applies all things specified by the wsdl file...
This request works:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="Sendcockpit/API" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="Sendcockpit/API">
<env:Header>
<validate>
<userid>32027</userid>
<apikey>***********</apikey>
<version>1.0</version>
<mode>live</mode>
</validate>
</env:Header>
<env:Body>
<apiGetListDetails>
<ctListRequest>
<listID>72472</listID>
</ctListRequest>
</apiGetListDetails>
</env:Body>
</env:Envelope>

Resources