Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Integrating SOAP in your Rails Application

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 736
    Comment on it

    Hi Friends,

    Most of the large applications use SOAP for data transfer between two parties. So in rails we can also integrate SOAP support. For this there are multiple gems available. One of the mostly used gem is "savon". So here we will see, how we can integrate savon with rails to handle SOAP requests:


    1) Add savon gem to your Gemfile

    gem 'savon', '~> 2.11.0'

     

    2) Run the bundle to install the gem

    bundle install

     

    3) Require savon where you want to use its methods:

    require 'savon'

     

    4) After requiring savon, you need to create a client object for the target Url of the requesting service provider

    client = Savon.client(wsdl: 'http://service_providers_url')

     

    5) To know the operations available for the service provider, there is a method available:

    client.operations
    
    # => [:get_property_tab, :update_property_tab, :get_client_details]


    6) Now at last to get or update any kind of request depending upon the parameters required by the service, which can be either SOAP based XML or json. you need to hit call method. i.e.

    # For json data
    response = client.call(:get_property_tab, {property_id: 55})
    
    # For soap/xml data
    xml_data = "SOME_XML_CONVERTED_DATA"
    response = client.call(:get_property_tab, xml_data)


    7) To get the response, you need to get the body of the response:

    response.body
    # => {aptitude_scores: 55, success: true}


    Hope you liked reading this blog.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: