I am trying to connect to a company that uses SOAP remote procedure calls so I am using the Savon Gem. Here is what I have to setup the authentication:
require 'savon'
client = Savon.client(
wsdl: 'https://customdomain.companydomain.com:port/wsdlcode/wsdl/xmlBridge',
endpoint: 'https://customdomain.companydomain.com:port/endpointcode/soap/xmlBridge',
basic_auth: ["username", "password"],
env_namespace: :soapenv,
namespace_identifier: :web,
logger: Rails.logger,
log_level: :debug,
log: true,
:pretty_print_xml => true,
encoding: 'UTF-8'
)
This seems to work. I can even call "client.operations" to get a list of the functions that can be called. When I run
response = client.call(:get_active_employees)
to try to get an employee list, I get the error message:
Savon::SOAPFault ((SOAP-ENV:Server) The namespace prefix is not allowed to start with the reserved string "xml".)
Does anyone know how to fix this?
The issue here is that the wsdl is likely including incorrect namespaces that Savon is automatically adding into the xml that you are sending back in the request. If you look at the lib/savon/builder.rb file in the Savon Gem by using:
gem which savonto determine where your salon gem is located and then opening the enclosing gem folder in your IDE. Which should be something along the lines of
/Users/username/.rvm/gems/ruby-2.5.1/gems/savon-2.13.0/if your on a macOpen the builder.rb file
lib/savon/builder.rbHere you'll see a method namespaces which unfortunately includes all the parsed namespaces from the wsdl:
If that wsdl includes an invalid namespace it will be included right back in the output when you perform your call.
To fix this you need to add a new file in
config/initializers/savon_monkey_patch.rbthat contains the attached code:The key line being
identifier.match?(/^xml/)which will exclude any namespaces that begin with xml from your outgoing request. I hope this helps.