Timeout Errors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Charles A. Lackman

    Timeout Errors

    Hello,

    I have a desktop app that retrieves data from a web service, It has worked
    really good for over a year, but there is an ongoing problem that I have not
    been able to fix.

    When the client is not online, it take over 90 seconds for the application
    to through a exception that the underline connection is closed.

    This there a way to speed this up. Instead of it taking 90 seconds,
    something like 15 seconds?

    I am testing the connection to the web service by called a function called
    ISOnline.
    All it does is return a True

    If true is not returned then I do something else, but I still get a timeout
    exception...


    Any Assistance would be greatly appreciated.

    Thanks,

    Chuck


  • Peter Kelcey

    #2
    Re: Timeout Errors

    Chuck,

    The client-side timeout is specified by the Timeout property of the
    proxy class.
    I.e.

    Service1 ws = new Service1();
    ws.Timeout = 90000; // 90 seconds
    ws.DoMethod();

    I would also suggest that instead of just waiting for connection
    timeout, you may want to pro-actively determine if the machine is
    connected or not, before you even make the webservice call. This would
    let your application begin to act more like a smart client, that is
    able to determine it's own status and take the approriate actions based
    on that status.

    There are a couple of methods you can use for to determine if you are
    online or not. The first one is pretty simple to use and determines if
    the machine has a valid internet connection. This is the same method
    used by IE to determine if the user if online or offline.

    using System.Runtime. InteropServices ;

    [DllImport("wini net.dll")]
    private extern static bool InternetGetConn ectedState( out int
    connectionDescr iption, int reservedValue ) ;

    public bool IsConnected()
    {
    int connectionDescr iption = 0;
    return InternetGetConn ectedState(out connectionDescr iption, 0);
    }


    This second method will tell you if you are connected to a network and
    identifies the type, i.e. LAN or WAN.

    using System.Runtime. InteropServices ;

    [DllImport("sens api.dll" ) ]
    public static extern bool IsNetworkAlive( out int flags );

    if( IsNetworkAlive( out flags ) )
    MessageBox.Show ( "Network connected, flags:" + flags.ToString( ) );
    else
    MessageBox.Show ( "Network NOT connected!" );

    Your third option, scans your network devices and tells you if any of
    them are connected. This is the only one that will detect an unplugged
    cable scenario. I.e. You were connected, but the cable was unplugged
    since then. The previous two methods would still return a incorrect
    "true" value under that condition.

    using System.Runtime. InteropServices ;
    using System.Manageme nt;

    static bool IsActiveConnect ion()
    {
    ManagementClass managementClass = new ManagementClass ( @"root\WMI",
    @"MSNdis_MediaC onnectStatus", null );
    ManagementObjec tCollection DeviceCollectio n =
    managementClass .GetInstances() ;

    foreach( ManagementObjec t device in DeviceCollectio n )
    {
    string name = (string) device["InstanceNa me"];
    bool active = (bool) device["Active"];
    uint status = (uint) device["NdisMediaConne ctStatus"];
    if (status == 0)
    {
    //We've found at least one live connection
    return(true);
    }
    }
    //No live connections were found
    return(false);
    }

    Hope that helps

    Peter Kelcey

    Comment

    Working...