Using Ruby to connect to the Microsoft SOAP web service, which requires a username, password, and security certificate (.cer file) to connect to it

First, a little background:

I have already managed to connect to the Microsoft SOAP web service using C #. To use this web service, I have to provide a username and password in C # code. I must also install a security certificate (in .cer format) in the "Root Certification Authorities" section of system certificates. The service address is the secure address "https: //".

(By the way, the C # class that I use to connect to the service was automatically generated for me using the command line tool "svcutil.exe https: //address.of.service ")

Here is my question:

How to connect to this web service using Ruby? I donโ€™t know where to start. I do not know where my .cer file, username and password should go exactly. Any ideas?

Additional Information:

Using these instructions for C #, I was able to find out what exactly the XML message was sent and what XML message was received. These XMLs are fairly straightforward, but "https: //" never appears in them, although the web service address is HTTPS. I am not sure why this is so. I believe that sending and receiving messages from the service is just a separate issue from the actual connection to the service.

+4
source share
2 answers

I can recommend using Savon to work with SOAP in Ruby!

I assume this is the normal HTTP authentication you are dealing with, in which case it should be pretty simple. Simply:

client = Savon::Client.new do http.auth.basic "user_name", "password" # Use a local wsdl wsdl.document = File.expand_path("../wsdl/ebay.xml", __FILE__) # or from internet wsdl.document = "http://service.example.com?wsdl" # to list SOAP actions client.wsdl.soap_actions end 

(this is just from my head, so it can be turned off a bit) Read the link I posted and let me know if you cannot figure it out. :)

The certificate file is used for your computer to accept the identifier of the server to which you want to connect. If you installed it on your computer, I donโ€™t think you need to do anything in this part.

EDIT

If you cannot use the WSDL file, you will have to manually create the xml, which is pretty ugly, but possible if it is not. Nokogiri can be used to create an xml document, then you can just POST the XML document to the correct URL. I have good experience using httpi-ntlm for authentication.

+4
source

What you say here is transport security, not message security. The certificate installed on the Windows server is used to encrypt the SSL connection. What you need to do with Ruby, make sure that when you connect a client certificate that matches the installed certificate, it is used to encrypt your SSL connection.

This is half the server management (installing an SSL certificate) and half the code (make sure you are using the appropriate certificate).

I'm not a Ruby expert, but I think you'll need something like this to use the x509 certificate in your connection. WCF uses the configuration file to do the same, while traditional ASMX services use the code to do this.

+1
source

Source: https://habr.com/ru/post/1403715/


All Articles