Custom binding savon

I have a wonderful task working with a massive SOAP api with Rails. The SOAP service has three different bindings; wsHttpBinding, wsHttpBinding with x509 and user binding. I can hit two endpoints only with wsHttpBinding, but the third requires a username and password that does not work with this. I avoid x509 because of the certificate, and user binding works fine in SoapUI, but with Savon I get the following error.

A message with an action "cannot be processed at the receiver due to a ContractFilter mismatch in the EndpointDispatcher. This may be due to a contract mismatch (action mismatch between the sender and the recipient) or a binding / security mismatch between the sender and the recipient. Make sure the sender and recipient have the same contract and the same binding (including security requirements, such as message, transport, no).

I took the exact XML that was generated using Savon and put into SoapUI, and it works.

Could this be a related issue? And is there a way to say to use this custom binding?

Here is the user binding I found in App.config

<bindings> <customBinding> <binding name="cust"> <textMessageEncoding messageVersion="Soap12" /> <httpTransport /> </binding> <binding name="cust1"> <textMessageEncoding messageVersion="Soap12" /> <httpTransport /> </binding> <binding name="cust2"> <textMessageEncoding messageVersion="Soap12" /> <httpTransport /> </binding> </customBinding> </bindings> <endpoint address="http://api.xyz.com/stuff.svc/cust" binding="customBinding" bindingConfiguration="cust" contract="stuff.Xstuff" name="cust" /> 

Edit # 1

Here is my current client setup that helps.

 @client = Savon.client( wsdl: 'http://api.xyz.com/stuff.svc?wsdl', wsse_auth: %w'username password', wsse_timestamp: true, raise_errors: false, log: true, log_level: :debug, soap_version: 2, pretty_print_xml: true, convert_request_keys_to: :none, use_wsa_headers: true, headers: {'Content-Type' => 'application/soap+xml; charset=utf-8'} 

Edit # 2

I found a problem. Savon did not set the action to Content-Type, such as SoapUI. Thanks to @RicardoPontual, offering to try again comparing the Savon request and SoapUI, it made me take a closer look at it and notice the problem.

 headers: {'Content-Type' => 'application/soap+xml;charset=UTF-8;action="tempuri.org/stufโ€Œโ€‹f/set_table_stuff"'} 
+5
source share
2 answers

Based on what we said in the comments, adding a header with the action of the operation you want to use can solve the problem, something like this:

 @client = Savon.client( wsdl: 'http://api.xyz.com/stuff.svc?wsdl', wsse_auth: %w'username password', wsse_timestamp: true, raise_errors: false, log: true, log_level: :debug, soap_version: 2, pretty_print_xml: true, convert_request_keys_to: :none, use_wsa_headers: true, headers: {'Content-Type' => 'application/soap+xml;charset=UTF-8;action="tempuri.org/stufโ€Œโ€‹f/set_table_stuff"'} ); 
+1
source

You need to set action="tempuri.org/stufโ€Œโ€‹f/set_table_stuff"' in the Content-Type header, for example:

 @client = Savon.client( wsdl: 'http://api.xyz.com/stuff.svc?wsdl', wsse_auth: %w'username password', wsse_timestamp: true, raise_errors: false, log: true, log_level: :debug, soap_version: 2, pretty_print_xml: true, convert_request_keys_to: :none, use_wsa_headers: true, headers: {'Content-Type' => 'application/soap+xml; charset=UTF-8; action="tempuri.org/stufโ€Œโ€‹f/set_table_stuff";'} 
+2
source

All Articles