Search code examples
rubysoaprubygemswsdlsavon

How to fix Net::ReadTimeout in SOAP API using Savon Ruby gem?


My script works but due to some reason it is throwing Net::ReadTimeout error. I presume due to high number of connections to the API. Any way to delay timeout using Savon? Thanks.

wsdl = 'https://org.my.domain/webservices/myservice.asmx?WSDL'

# Open Client Webservice
client = Savon.client(wsdl: wsdl, ssl_verify_mode: :none, ssl_version: :TLSv1, convert_request_keys_to: :none)

# Connect to Webservice - Authenticate
response = client.call(:authenticate, message: { username: 'user', password: 'pwd', organization: 'org', domain: 'my.domain' })

Solution

  • You will want to increase the read timeout if you cannot decrease the amount of calls you are making to the API. In reality, your programs should always be respectful to the resource they are interacting with and should allow for other programs to access them without detracting from performance.

    If you did want to increase the read timeout, the syntax would depend what version you are using, for version 2.x:

    client = Savon.client(
        wsdl: wsdl,
        ssl_verify_mode: :none,
        ssl_version: :TLSv1,
        convert_request_keys_to: :none,
        open_timeout: 400,
        read_timeout: 400,
    )
    

    For version 3.x:

    client.http.send_timeout = 400
    client.http.receive_timeout = 400
    

    Be wary these are seconds.