views:

1002

answers:

7

Hi all, I've got a web service that I talk to from a PDA. In the same directory as the webservice asmx file, I have an html file that I pull a web request from in order to see if the directory is available.

I use the following code:

    /// <summary>
    /// Holds the web request for checking the connectivity.
    /// </summary>
    private static WebRequest m_WebRequest;


    /// <summary>
    /// Tests the connection to the provided URL.
    /// </summary>
    /// <param name="url">The URL to test.</param>
    /// <returns>True if the URL was resolved.</returns>
    public static bool TestUrl(string url)
    {

        try
        {


            // Ensure the url is valid
            url = url.Replace("http:\\", "http://");
            url = url.Replace("\\", "/");

            // Create the request
            m_WebRequest = WebRequest.Create(url);
            m_WebRequest.Timeout = 30000;

            // Get the request
            HttpWebResponse response = (HttpWebResponse)m_WebRequest.GetResponse();
            return true;

        }
        catch
        {
            m_WebRequest.Abort();
            return false;
        }

    }

The file I am getting the response for is always the same and is always accessible from my PC. It only seems to fail when the web service (in the same directory as the html file) errors. Could that be related?

Alternatively, is there a better way of seeing if that file exists over the web?

A: 

I exeperienced something like that when the link between PDA and internet fails. The WebRequest opens automatically the GPRS/HSDPA connection, maybe there's a problem at that level.

Zen
A: 

The error I am getting is just a timeout. I.e. it sits there until the 30seconds elapses, then falls over. What's annoying is it only happens when the web service fails or times out. It's like the web service failing is locking out the virtual directory.

There's no problem with the network link between the pda and the network. The webservice is locally on my network, so the internet doesn't come into play. I am just using the ActiveSync connection to let my PDA talk to the network.

GenericTypeTea
A: 

I find that half the problem is the device data connection. Try to manually type in the url into pocket IE on the device. If that works then your application should work. If it doesn't then you need to sort out your device data connection setup first. If your connected via ActiveSync (or WMDC) try to change the connection settings between Auto / Work / Internet, that sometimes helps.

As for how to test to see if the URL exists. Use a HEAD request instead of a GET request. That way you don't get all the data just the headers returned. I'm not a C# guy so I can't help with how to do the HEAD request instead of a GET request.

Shane Powell
A: 

Hi, the URL always works for IE on the mobile - it just doesn't work from the application. So its as though the application is locked out from making requests, or there's something wrong in my test code (as per my original post).

GenericTypeTea
A: 

Yes, get rid of the catch-all and get a specific exception message so you can tell more about what's going on.

I find I get errors a lot in System.Net.HttpWebRequest.finishGetResponse() when working in CF.NET, and they are most likely interruptions in the data connection due to poor signal.

Jake Stevenson
A: 

I used the Ping component of SDF 2.3 instead. The error was always a timeout and only happened when the webservice errored. Still unexplained, but I guess the check I was doing was a bad way of doing it anyway.

GenericTypeTea
A: 

I've got the same problem. I can make 2 queries with it, but when i try the third it fails.