Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Infinite Timeout after second HttpWebRequest

Hei Guys,

we have a iOS Application which communicates via a WCF Webservice with our own Webservice. We implemented the WcfProxy with Visual Studio and all Works well. Now one of our customers has a unique problem. He uses a vpn to obtain a connection from the mobile device to our webservice. Sometimes the vpn is not correctly loaded and our app tries to open a connection to an internal webservice adress. If this happens the first request via the HttpWebRequest (used in the generated WcfProxy) will trigger after the set timeout period a timeout exception (so far, so good). Now if we call a secondary method of the WcfProxy to this (not existing) Url the HttpWebRequest will never come back and will stay forever. Only we can accompolish a connection to the vpn, then the function will correctly excuted.

This problem can be replicated by following simple function:

    //---Format for Forums-Post changed to don't look like a Url ;-)
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https" + "://" + "sg.eurowig.local" + "/" + "abc.html"); 


        request.Timeout = 1000;
        request.ContinueTimeout = 1000; //Try
        request.ReadWriteTimeout = 1000;  //Try
        request.KeepAlive = false;  //Try
        request.ServicePoint.MaxIdleTime = 1000;  //Try
        request.Method = "HEAD"; //Try
        try
        {
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                //Console.Log("We reached the destination");
            }
        }
        catch (WebException exc)
        {
            //Console.Log(exc);
        }
        finally
        {
            request.Abort(); //Try
            request = null; //Try
            GC.Collect(); //Try
        }

My expirience so far:

  • Compiled on Visual Studio for Mac 7.7.3 on an iPhone 8 Plus with iOS 12.1
  • >> No timeout on second call
  • Compiled with Visual Studio for Windows 2017 on an iPhone 8 Plus with iOS 12.1
  • >> No timeout on second call
  • Tried with an not existing URL like "my.domain.that.does.not.exist"
  • >> Direct exception - Cant resolve hostname << Works
  • Different settings in the HttpWebRequest Object, as u see on the //Try comment each line...
  • >> No timeout on second call

Anyone an ideas, how to run into the timeout in the second call?

thanks in advance too you guys,
Sascha

Answers

  • Tried this now in the Simulator and there it works ... quiet well... In Simulator the Timeout works, on a real device like mine it doesn't work...

Sign In or Register to comment.