Ruby SOAP client communication with Microsoft .NET webservice

Discussion in 'Ruby' started by Kishore, Dec 10, 2005.

  1. Kishore

    Kishore Guest

    Hi:

    I am trying to interface a SOAP client written in Ruby with a .NET
    webservice. However, I am unable to get the client to construct the
    correct SOAP request for methods with one string argument. My ruby
    client file has the following code:

    require 'soap/wsdlDriver'
    require 'cgi'

    WSDL_URL = "http://instrument1/orbitws/orbitinterferencews.asmx?WSDL"
    soap_client = SOAP::WSDLDriverFactory.new(WSDL_URL).create_rpc_driver

    # Log SOAP request and response
    soap_client.wiredump_file_base = "soap-log.txt"

    # Call reset method.
    result = soap_client.resetIntWS(nil)
    puts result.inspect

    # Call stopGenerate method.
    result = soap_client.stopGenerate('1')
    puts result.inspect

    The first method call works but the second one fails to construct the
    SOAP request with the single argument. We tried using double quotes as
    well but that did not work either.

    The SOAP request we want should like like:

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
    <stopGenerate xmlns="http://instrument1.orbit-lab.org/OrbitWS/">
    <request_id>string</request_id>
    </stopGenerate>
    </soap:Body>
    </soap:Envelope>

    However, our SOAP request looks like:

    <?xml version="1.0" encoding="utf-8" ?>
    <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <env:Body>
    <n1:stopGenerate
    xmlns:n1="http://instrument1.orbit-lab.org/OrbitWS/">
    </n1:stopGenerate>
    </env:Body>
    </env:Envelope>

    Note that the "<request_id>string</request_id>" is missing. Can you
    please tell me why this is happening. I am using ruby v1.8.4 on a
    debian linux 2.6.11-1-686-smp.

    Thanks,
    Kishore
    Kishore, Dec 10, 2005
    #1
    1. Advertising

  2. Kishore

    Kero Guest

    ><?xml version="1.0" encoding="utf-8"?>
    ><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    > xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    > <soap:Body>
    > <stopGenerate xmlns="http://instrument1.orbit-lab.org/OrbitWS/">
    > <request_id>string</request_id>
    > </stopGenerate>
    > </soap:Body>
    ></soap:Envelope>
    >
    > However, our SOAP request looks like:
    >
    ><?xml version="1.0" encoding="utf-8" ?>
    ><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    > xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
    > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    > <env:Body>
    > <n1:stopGenerate
    > xmlns:n1="http://instrument1.orbit-lab.org/OrbitWS/">
    > </n1:stopGenerate>
    > </env:Body>
    ></env:Envelope>


    How would the call to stopGenerate know that '1' is a request id?

    I have had success with using Structs.

    Request = Struct.new:)request_id)
    soap.stopGenerate(Request.new('1'))

    Hth,
    Kero.
    Kero, Dec 10, 2005
    #2
    1. Advertising

  3. Kishore

    Kishore Guest

    Hi Kero:

    Thanks a lot. That worked out. Would you know how to pass an array of
    strings as argument? I am trying to the following:

    Request = Struct.new:)request_id, :names, :values)
    result = soap_client.stopGenerate(Request.new("1", ["POWER", "FREQ"],
    ["-15", "5.18GHz"]))
    puts result.inspect

    This should generate the following SOAP request:

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
    <Generate xmlns="http://instrument1/OrbitWS/">
    <request_id>string</request_id>
    <names>
    <string>string</string>
    <string>string</string>
    </names>
    <values>
    <string>string</string>
    <string>string</string>
    </values>
    </Generate>
    </soap:Body>
    </soap:Envelope>

    However, it creates the following:

    <?xml version="1.0" encoding="utf-8" ?>
    <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <env:Body>
    <n1:Generate xmlns:n1="http://instrument1.orbit-lab.org/OrbitWS/">
    <n1:request_id>1</n1:request_id>
    <n1:names>
    <n1:string></n1:string>
    </n1:names>
    <n1:values>
    <n1:string></n1:string>
    </n1:values>
    </n1:Generate>
    </env:Body>
    </env:Envelope>

    Thanks,
    Kishore
    Kishore, Dec 10, 2005
    #3
  4. Kishore

    Guest

    On Sunday 11 December 2005 03:32 am, Kishore wrote:

    When using SOAP4R with .NET web services, you must use the ASPDotNetHander.

    @my_client.default_encodingstyle =
    SOAP::EncodingStyle::ASPDotNetHandler::Namespace

    Tsume

    > Hi Kero:
    >
    > Thanks a lot. That worked out. Would you know how to pass an array of
    > strings as argument? I am trying to the following:
    >
    > Request = Struct.new:)request_id, :names, :values)
    > result = soap_client.stopGenerate(Request.new("1", ["POWER", "FREQ"],
    > ["-15", "5.18GHz"]))
    > puts result.inspect
    >
    > This should generate the following SOAP request:
    >
    > <?xml version="1.0" encoding="utf-8"?>
    > <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    > xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    > <soap:Body>
    > <Generate xmlns="http://instrument1/OrbitWS/">
    > <request_id>string</request_id>
    > <names>
    > <string>string</string>
    > <string>string</string>
    > </names>
    > <values>
    > <string>string</string>
    > <string>string</string>
    > </values>
    > </Generate>
    > </soap:Body>
    > </soap:Envelope>
    >
    > However, it creates the following:
    >
    > <?xml version="1.0" encoding="utf-8" ?>
    > <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    > xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
    > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    > <env:Body>
    > <n1:Generate xmlns:n1="http://instrument1.orbit-lab.org/OrbitWS/">
    > <n1:request_id>1</n1:request_id>
    > <n1:names>
    > <n1:string></n1:string>
    > </n1:names>
    > <n1:values>
    > <n1:string></n1:string>
    > </n1:values>
    > </n1:Generate>
    > </env:Body>
    > </env:Envelope>
    >
    > Thanks,
    > Kishore
    , Dec 10, 2005
    #4
  5. Kishore

    Kero Guest

    > Thanks a lot. That worked out. Would you know how to pass an array of
    > strings as argument? I am trying to the following:
    >
    > Request = Struct.new:)request_id, :names, :values)
    > result = soap_client.stopGenerate(Request.new("1", ["POWER", "FREQ"],
    > ["-15", "5.18GHz"]))


    I have something like
    Request = Struct.new(...)
    Names = Struct.new(...)
    Request.new(1, Names.new(["power", "freq"], Values.new([...])

    i.e. the arrays wrapped in their own structs.

    However, I needed different soap requests; I got to it after a *detailed*
    look (yuck) at the wsdl, I suppose yours might look different. YMMV.

    And here my experience ends. I got working what I needed, then stopped
    looking.

    Bye,
    Kero.
    Kero, Dec 12, 2005
    #5
  6. Kishore

    Kishore Guest

    Hi Kero:

    Thanks for getting back to me. I got it to work after reading through
    some of nahi's emails (thanks to him). The steps I followed were as
    follows:

    1. Download soap4r from SVN.
    svn co http://dev.ctor.org/svn/soap4r/trunk/bin soap4r

    This will result in two files being downloaded - wsdl2ruby.rb and
    xsd2ruby.rb. The one I used was the wsdl2ruby.rb.

    2. Generate sample SOAP client file

    ruby wsdl2ruby.rb --wsdl http://location_of_WSDL --type client

    This will result in the creation of three files - default.rb,
    defaultDriver.rb and WSClient.rb. The sample client file is
    WSClient.rb. Inside this file, I found all the remote methods and "nil"
    arguments being passed to them. For e.g., I had a remote method defined
    as follows in my web-service:

    string observe (string req_id, string[] names, string[] values);

    The second and third argument for this file were vectors of strings.

    In the ruby client file, this method was exposed as follows:

    obj = WSSoap.new(nil)

    parameters = nil
    puts obj.observe(parameters)

    So, even though my remote method should have three arguments, here
    there is only one. According to nahi's email, I needed to construct a
    hash table and pass that as the single argument.

    3. Pass actual arguments.
    name = ['CENTER', 'SPAN', 'SCALE', 'YREF', 'INTERVAL']
    val = ['5.18 GHz', '2.95 MHz', '4.00', '-68.70', '30000']
    parameters = {
    'req_id' => '1',
    'names' => {:string => name},
    'values' => {:string => val}
    }
    result = obj.observe(parameters)
    puts result.inspect

    Hope that helps,
    Kishore

    Kero wrote:
    > > Thanks a lot. That worked out. Would you know how to pass an array of
    > > strings as argument? I am trying to the following:
    > >
    > > Request = Struct.new:)request_id, :names, :values)
    > > result = soap_client.stopGenerate(Request.new("1", ["POWER", "FREQ"],
    > > ["-15", "5.18GHz"]))

    >
    > I have something like
    > Request = Struct.new(...)
    > Names = Struct.new(...)
    > Request.new(1, Names.new(["power", "freq"], Values.new([...])
    >
    > i.e. the arrays wrapped in their own structs.
    >
    > However, I needed different soap requests; I got to it after a *detailed*
    > look (yuck) at the wsdl, I suppose yours might look different. YMMV.
    >
    > And here my experience ends. I got working what I needed, then stopped
    > looking.
    >
    > Bye,
    > Kero.
    Kishore, Dec 21, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    1
    Views:
    1,326
    smith
    Dec 8, 2004
  2. Sham Ramakrishnan
    Replies:
    2
    Views:
    8,336
    Sham Ramakrishnan
    Jul 1, 2003
  3. SpamProof
    Replies:
    0
    Views:
    532
    SpamProof
    Oct 21, 2003
  4. Bruce

    client-to-client communication via SOAP

    Bruce, Mar 21, 2005, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    240
    [MSFT]
    Mar 28, 2005
  5. Bruce

    client-to-client communication via SOAP

    Bruce, Mar 24, 2005, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    136
    Bruce
    Mar 24, 2005
Loading...

Share This Page