Ruby(2.0) & Savon(2) SOAP client - returning nil SOAP operation - ruby-on-rails

I am trying to integrate my rails app with SOAP based web-service.
Being a novice in SOAP, I referred this to get started.
My First step was to create a client using Savon:
client = Savon.client(wsdl: "https://xxxx.xxxx.xxxx/Reg/ABCRegService.svc?wsdl")
Now, when I do client.operations, I get a []
The wsdl looks something like this(I have masked value fields for security)
<wsdl:definitions name="some_name" targetNamespace="some_targetNamespace">
<wsdl:import namespace="some_Namespace1" location="some_nameService.svc?wsdl=wsdl0"/>
<wsdl:types>
<xsd:schema targetNamespace="some_targetNamespaceImports">
<xsd:import schemaLocation="http://example.net/some_name/some_Service.svc?xsd=xsd0" namespace="some_targetNamespace"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="some_name_RegisterTool_InputMessage">
<wsdl:part name="parameters" element="tns:RegisterTool"/>
</wsdl:message>
<wsdl:message name="some_name_RegisterTool_OutputMessage">
<wsdl:part name="parameters" element="tns:RegisterToolResponse"/>
</wsdl:message>
<wsdl:message name="UnregisterToolRequest">
<wsdl:part name="parameters" element="tns:UnregisterToolRequest"/>
</wsdl:message>
<wsdl:message name="UnregisterToolRequest_Headers">
<wsdl:part name="AuthenticationHeader" element="tns:AuthenticationHeader"/>
</wsdl:message>
<wsdl:message name="UnregistrationResult">
<wsdl:part name="parameters" element="tns:UnregistrationResult"/>
</wsdl:message>
<wsdl:portType msc:usingSession="false" name="some_name">
<wsdl:operation name="RegisterTool">
<wsdl:input wsaw:Action="some_targetNamespacesome_name/RegisterTool" message="tns:some_name_RegisterTool_InputMessage"/>
<wsdl:output wsaw:Action="some_targetNamespacesome_name/RegisterToolResponse" message="tns:some_name_RegisterTool_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="UnregisterTool">
<wsdl:input wsaw:Action="some_targetNamespacesome_name/UnregisterTool" name="UnregisterToolRequest" message="tns:UnregisterToolRequest"/>
<wsdl:output wsaw:Action="some_targetNamespacesome_name/UnregisterToolResponse" name="UnregistrationResult" message="tns:UnregistrationResult"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:service name="some_name">
<wsdl:port name="WSHttpBinding_some_name" binding="i0:WSHttpBinding_some_name">
<soap12:address location="https://example.net/Dcsome_name/some_nameService.svc"/>
<wsa10:EndpointReference>
<wsa10:Address>https://example.net/Dcsome_name/some_nameService.svc</wsa10:Address>
<Identity>
<Dns>localhost</Dns>
</Identity>
</wsa10:EndpointReference>
</wsdl:port>
</wsdl:service>
I looked into similar questions such as this. When I tried creating client in the suggested manner
client = Savon.client(
endpoint: 'proper_endpoint',
soap_action: "proper_soap_action",
namespace: 'proper_namespace',
convert_request_keys_to: :camelcase,
env_namespace: :soapenv
)
,I got:
:in `method_missing': Unknown global option: :soap_action (Savon::UnknownOptionError).
Any Ideas on how to get through this?
Environment:
OS:Windows 7(Installed rails using RailsInstaller)
Ruby version: 2.0.0
Savon: 2
Rails 4.1.8
Update:
I tried hitting the same WSDL from SOAPUI.
To make it work in SOAPUI,
I had to
set WS-Addressing property to true,
Check the checkbox for Add default wsa:to,
Use <![CDATA[]> to pass identifiers parameters.
Any leads on how to set these things in while creating Savon client?

Your process of retrieving operations of the wsdl is perfectly right. I checked the wsdl in 'Soap UI' & it seems like that the WSDL has some error. And this is why you are not getting any operations as the wsdl is not providing any definition.
Error loading [https://xx.xxxx.xxx/DcRegistration/DCRegistrationService.svc?wsdl=wsdl0]: java.io.IOException: Attempted read from closed stream

The issue was due to incorrect parsing of WSDL. In the wasabi gem, lib/parser.rb on line 136, the current XPATH search is:
wsdl:definitions/wsdl:binding/wsdl:operation', 'wsdl' => WSDL
However, the WSDL I am referring has elements organised differently and I had to tweak the above line to:
'wsdl:definitions/wsdl:portType/wsdl:operation', 'wsdl' => WSDL
Here is a link for the same issue in github: https://github.com/savonrb/savon/issues/702

Related

How is the OperationContractAttribute.Action value is set?

I'm using the "Add Service Reference" option in Visual Studio in order to create a proxy class using a WSDL file given to me by a third party.
I got 2 versions of the WSDL - we'll call them "OLD" and "NEW".
Even though the WSDL files suppose to be the same (the new one got updated methods version) , when creating the proxy classes I get a different values in the OperationContractAttribute.Action.
In the OLD wsdl it looks like that:
[System.ServiceModel.OperationContractAttribute(Action="http://webservices.amadeus.com/SATRQT_13_2_1A", ReplyAction="*")]
In the new wsdl it looks like that:
[System.ServiceModel.OperationContractAttribute(Action="http://xml.amadeus.com/AmadeusWebServicesPT/Air_MultiAvailabilityRequest", ReplyAction="http://xml.amadeus.com/AmadeusWebServicesPT/Air_MultiAvailabilityResponse")]
I can't figure it out from where the "Action" value is taken from.
In the old WSDL the value is valid , but in the new WSDL is completely wrong and I get an exception when trying to use the service in the WS
When I look in the OLD wsdl file i can see a "soapAction" with the same value; this seems to be where it's taken from. However in the NEW wsdl there is a value there exactly like in the OLD wsdl
<wsdl:operation name="Air_MultiAvailability">
<soap:operation soapAction="http://webservices.amadeus.com/SATRQT_13_2_1A" />
Can anyone direct to me to the right place?
Update
After reading some more on the "Action" element I realized that the value that I see in the NEW wsdl is the DEFAULT value (see https://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontractattribute.action(v=vs.110).aspx)
Now I need to understand WHY in the OLD wsdl file we get the Action value to be the correct one (I'm guessing from the soapAction defined in the wsdl file under the correct operation) and in the NEW wsdl there is no match and a default value is populated ?
ok found the problem!
in the WSDL file there were multiple "Operation" with the same name
<wsdl:portType name="WebServices">
<wsdl:operation name="DoSomething">
<wsdl:input message="ns:DoSomething_1_1" />
<wsdl:output message="ns:DoSomething_1_1" />
</wsdl:operation>
<wsdl:operation name="DoSomething">
<wsdl:input message="ns:DoSomething_2_2" />
<wsdl:output message="ns:DoSomething_2_2" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding type="ns:WebServices" name="WebServicesBinding">
<wsdl:operation name="DoSomething">
<soap:operation soapAction="http://webservices.my.com/DoSomething_1_1" />
</wsdl:operation>
<wsdl:operation name="DoSomething">
<soap:operation soapAction="http://webservices.my.com/DoSomething_2_2" />
</wsdl:operation>
</wsdl:binding>
the "DoSomething" got 2 version in this example 1.1 and 2.2
once i deleted\renamed ALL duplicated operations (i had multiple of them) the "Action" value was taken from the "soapAction" element
hope this will help someone in the future !

generate xsd and set fields as required in JAX-WS

The following is an implementation of the specification outlined in the above picture.
#WebService
#SOAPBinding(style = Style.DOCUMENT)
public interface WithdrawService {
#WebMethod
public Response withdraw(
#WebParam(name="CORPCODE") String corpcode,
#WebParam(name="SERVCODE") String servcode,
#WebParam(name="AMOUNT") double amount,
#WebParam(name="CCYID") String ccyid,
#WebParam(name="ACCTNO") String acctno,
#WebParam(name="REFVAL1") String refvel1,
#WebParam(name="REFVAL2") String refval2,
#WebParam(name="TRANREF") String tranref,
#WebParam(name="DESC") String desc,
#WebParam(name="LICENSEID") String licenseid,
#WebParam(name="LICENSEKEY") String licensekey
);
}
The following WSDL is generated when a user accesses the ?wsdl link.
<!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b.
-->
<!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b.
-->
<definitions targetNamespace="http://withdraw.kbz.nirvasoft.com/" name="WithdrawServiceImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://withdraw.kbz.nirvasoft.com/" schemaLocation="http://localhost:8080/WithdrawService/withdraw?xsd=1"/>
</xsd:schema>
</types>
<message name="withdraw">
<part name="parameters" element="tns:withdraw"/>
</message>
<message name="withdrawResponse">
<part name="parameters" element="tns:withdrawResponse"/>
</message>
<portType name="WithdrawService">
<operation name="withdraw">
<input wsam:Action="http://withdraw.kbz.nirvasoft.com/WithdrawService/withdrawRequest" message="tns:withdraw"/>
<output wsam:Action="http://withdraw.kbz.nirvasoft.com/WithdrawService/withdrawResponse" message="tns:withdrawResponse"/>
</operation>
</portType>
<binding name="WithdrawServiceImplPortBinding" type="tns:WithdrawService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="withdraw">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="WithdrawServiceImplService">
<port name="WithdrawServiceImplPort" binding="tns:WithdrawServiceImplPortBinding">
<soap:address location="http://localhost:8080/WithdrawService/withdraw"/>
</port>
</service>
</definitions>
We are unhappy with two things.
We do not get any xsd documents for the types used.
We cannot say whether fields are required in the generated wsdl.
I would like to know how we could achieve them using our code.
You can get your XSD from
http://localhost:8080/WithdrawService/withdraw?xsd=1
Depending on the server you use you can ask JAX-WS to generate embedded XSD file. Alternatively you can ask JAX-WS to use you own WSDL.

WSDL - understanding message definitions

I am trying to understand the structure of wsdl definitions, looking at the example found here.
I get the service, portType and operation parts, it's at the messages where I have a problem "reading" the specification.
So, just focusing at a single message (multiply), and ignoring the rest, I see a structure like:
<wsdl:definitions..>
<wsdl:types>
<xsd:schema>
<xsd:element name="multiply" type="tns:multiply"/>
<xsd:complexType name="multiply">
...
</xsd:complexType>
</xsd:schema>
</wsdl:types>
...
<wsdl:message name="multiply">
<wsdl:part element="tns:multiply" name="parameters"/>
</wsdl:message>
...
<wsdl:portType>
...
</wsdl:portType>
<wsdl:service>
...
</wsdl:service>
</wsdl:definitions>
Can anyone provide a sentence explaining what multiply is, beginning with: "multiply is a message that's ..." ??
Moreover, could somebody explain how many uses of the name "multiply" we have? I think there are multiple and we seem to avoid clashes through the use of XML namespaces and perhaps different "namespaces" for XML elements and types.
multiply is a message containing a single part, named parameters, consisting of the single element, tns:multiply. That element is of type tns:multiply.
I used XMLspy to fill this example out a bit:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tns="http://new.webservice.namespace" targetNamespace="http://new.webservice.namespace">
<wsdl:types>
<xs:schema targetNamespace="http://new.webservice.namespace" elementFormDefault="qualified">
<xs:complexType name="multiply">
<xs:sequence>
<xs:element name="x" type="xs:int"/>
<xs:element name="y" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:element name="multiply" type="tns:multiply"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="multiply">
<wsdl:part name="parameters" element="tns:multiply"/>
</wsdl:message>
<wsdl:portType name="NewPortType">
<wsdl:operation name="NewOperation">
<wsdl:input message="tns:multiply"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="NewBinding" type="tns:NewPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="NewOperation">
<soap:operation soapAction="urn:#NewOperation"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="NewService">
<wsdl:port name="NewPort" binding="tns:NewBinding">
<soap:address location="No target address"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
This leads to the following SOAP request:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<m:multiply xmlns:m="http://new.webservice.namespace">
<m:x>0</m:x>
<m:y>0</m:y>
</m:multiply>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

svcutil doesn't import fault when importing wsdl

when generating a proxy class from a wsdl which I got from a customer, I get the following warning from svcutil:
Warning: Fault named "ContractException" in operation "create" cannot be imported.
Unsupported WSDL, the fault message part must reference an element. This fault message
does not reference an element. If you have edit access to the WSDL document, you can fix
the problem by referencing a schema element using the 'element' attribute.
So, here are the parts from the wsdl in which the ContractException is mentioned
<schema targetNamespace="http://exceptions.webservice"
xmlns="http://www.w3.org/2001/XMLSchema" xmlns:impl="http://webservice"
xmlns:intf="http://webservice"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="ContractException">
<sequence>
<element name="message" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<element name="ContractException" nillable="true" type="tns3:ContractException"/>
</schema>
<wsdl:message name="ContractException">
<wsdl:part name="fault" type="tns3:ContractException"/>
</wsdl:message>
<wsdl:portType name="Contract">
<wsdl:operation name="create" parameterOrder="pApiKey pContractData">
<wsdl:input message="impl:createRequest" name="createRequest"/>
<wsdl:output message="impl:createResponse" name="createResponse"/>
<wsdl:fault message="impl:ContractException" name="ContractException"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:fault name="ContractException">
<wsdlsoap:fault encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
name="ContractException" use="encoded"/>
</wsdl:fault>
I cannot find any problems in this wsdl, but hopefully anyone can give me a hint what I have to change so my proxy gets generated successfully.
The wsdl was donwloaded from the webserver, so I can edit my local copy (which I use for generating the proxy class).
Based on the error message displayed, the fault needs to be wrapped inside an element, i.e. -
instead of:
<wsdl:message name="ContractException">
<wsdl:part name="fault" type="tns3:ContractException"/>
</wsdl:message>
you need to do this:
<wsdl:message name="ContractException">
<wsdl:part name="fault" element="tns3:ContractException"/>
</wsdl:message>

Why WSDL introduce wsdl:message?

Why WSDL introduces wsdl:message? And message parts?
What the advantage they could bring over the direct using of the XSD in the operations parameters (input, output, fault)?
How they (wsdl messages with wsdl message parts) can be more abstract then XSD?
Why it is not organized for example that way:
<operation name="GetEndorsingBoarder">
<input type="xsd:string"/>
<output type="xsd:string, xsd:int, xsd:boolean"/>
<fault "type="xsd:string""/>
</operation>
I got it:
Messages not just specify operation's parameters.
Messages and theirs parts are referred in the bindings. It should be possible to bind different parts differently:
<message name="m1">
<part name="body" element="tns:GetCompanyInfo"/>
</message>
<message name="m2">
<part name="body" element="tns:GetCompanyInfoResult"/>
<part name="docs" type="xsd:string"/>
<part name="logo" type="tns:ArrayOfBinary"/>
</message>
<portType name="pt1">
<operation name="GetCompanyInfo">
<input message="m1"/>
<output message="m2"/>
</operation>
</portType>
<binding name="b1" type="tns:pt1">
<operation name="GetCompanyInfo">
<soap:operation soapAction="http://example.com/GetCompanyInfo"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<mime:multipartRelated>
<mime:part>
<soap:body parts="body" use="literal"/>
</mime:part>
<mime:part>
<mime:content part="docs" type="text/html"/>
</mime:part>
<mime:part>
<mime:content part="logo" type="image/gif"/>
<mime:content part="logo" type="image/jpeg"/>
</mime:part>
</mime:multipartRelated>
</output>
</operation>
</binding>
I have missed this since "non SOAP 'literal'" bindings are so uncommon.
A XSD describes the DATA aspects, for example data aspects of webservice call whereas the WSDL describes the purpose of the web services (method calls). You cannot typically figure out the method calls from your data alone.
Check out Cheeso and Marc answers on Generating a WSDL from an XSD file
EDIT: source
The message describes the data being exchanged between the web services' provider and consumer and each web service has two messages:
1) input: parameters of the web service
2) output: return data from the web service
Each message has zero or more part parameters (one for each parameter of the web service's function) Each part parameter associates with a concrete type defined in the types container element.
<message name="SayHelloRequest">
<part name="firstName" type="xsd:string"/>
</message>
<message name="SayHelloResponse">
<part name="greeting" type="xsd:string"/>
</message>
Here, two message elements are defined. The first represents a request message SayHelloRequest, and the second represents a response message SayHelloResponse.
Each of these messages contains a single part element. For the request, the part specifies the function parameters; in this case, we specify a single firstName parameter. For the response, the part specifies the function return values; in this case, we specify a single greeting return value.

Resources