Bug 1669 - PROBLEM WITH HTTPS WCF WEBREQUEST THREAD POOL AFTER WCF ASYNC CALL
Summary: PROBLEM WITH HTTPS WCF WEBREQUEST THREAD POOL AFTER WCF ASYNC CALL
Status: RESOLVED NORESPONSE
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.0
Hardware: Macintosh Mac OS
: High normal
Target Milestone: 6.4 (async)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-10-24 18:06 UTC by Alejandro V
Modified: 2013-07-09 02:34 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description Alejandro V 2011-10-24 18:06:56 UTC
MY CODE WAS WORKING PERFECT WITH IOS 4, WHEN UPGRADING TO IOS 5 THEN I START GETTING ISSUES WITH THE THREADING.

FOR EXAMPLE:

I HAVE THIS CODE:

ThreadPool.QueueUserWorkItem( delegate{
                                if(AppDelegate.MainAppDelegate.IsOnline()){

THAT CHECKS IF THERE IS INTERNET CONNECTION USING MIGUEL'S REACHABILITY CODE. THE FIRST TIME IT EXECUTES ISONLINE() METHOD IS WORKS PERFECT, THE SECOND TIME IT SAYS THERE IS NO INTERNET CONNECTION. IF I REMOVE THREADING WORK FINE, WITH THREAD THE PROBLEM APPEARS. 

THANKS.

ALEJANDRO
Comment 1 Alejandro V 2011-10-24 19:39:06 UTC
I JUST MAKE ANOTHER TEST AND FIGURE OUT THE FOLLOWING:

THE THREAD STRANGE BEHAVOIR HAPPENS EXACTLY AFTER I CALL A WCF SERVICE:

svc.VerifyUserAsync (_organization, _userName, ....

THIS IS THE FIRST WCF SERVICE THAT IS EXECUTED INTTHE APPLICATION, AFTER ITS CALLED THEN THE THREAD BEHAVOIR STARTS. IF I COMMENT THAT LINE WHERE THE SERVICE IS CALLED THEN THERE IS NO ISSUE WITH THE THREAD.

HOPE THAT HELPS!!
Comment 2 Sebastien Pouliot 2011-10-25 16:51:16 UTC
Please provide us with a small, self-contained, test case that we can use to duplicate the issue. Thanks.
Comment 3 Alejandro V 2011-10-26 22:25:23 UTC
Hi Sebastien, I found exactly the source of the issue and its very interesting.

The issue appears when you try to connect to a WCF Service using https and BasicHttpSecurityMode.Transport. In mono touch 4 was working fine.

I created a sample application that do this:

********************
/* UtilClient is generated using slsvcutil.exe from silverlight 3.0 tools */

UtilClient svc = new UtilClient (new BasicHttpBinding (BasicHttpSecurityMode.Transport), new EndpointAddress ("https://mydomain.com/MobileWCFServices/util.svc"));
				
svc.VerifyUserCompleted += HandleAscVerifyUserCompleted;
svc.VerifyUserAsync (_organization, _userName, Utility.Common.Encrypt (_password.ToUpper ()), "", "mobileapp");


private void HandleAscVerifyUserCompleted (object sender, VerifyUserCompletedEventArgs e)
		{
			Console.WriteLine(AppDelegate.MainAppDelegate.IsOnline() == true ? "With Internet" : "Without Internet");
			Console.WriteLine(AppDelegate.MainAppDelegate.IsOnline() == true ? "With Internet" : "Without Internet");
}				

public bool IsOnline ()
		{
			ReachabilityStatus status = new ReachabilityStatus ();
			Thread thread = new Thread (ThreadedIsOnline);
			thread.IsBackground = true;
			thread.Start (status);
			
			bool terminated = thread.Join (2000);
			thread = null;
			return terminated && status.IsOnline;
			
		}
		
		private void ThreadedIsOnline (object state)
		{
			using (NSAutoreleasePool pool = new NSAutoreleasePool ()) {
				((ReachabilityStatus)state).IsOnline = Utility.Reachability.RemoteHostStatus () != Utility.NetworkStatus.NotReachable;
			}
		}

********************

If you run this you will see that you will get in the Console a  two lines the first says: With Internet and the second says Without Internet.

If you just change the endpoint of the WCF service to be just http and BasicHttpSecurityMode.None like:

UtilClient svc = new UtilClient (new BasicHttpBinding (BasicHttpSecurityMode.None), new EndpointAddress ("http://mydomain.com/MobileWCFServices/util.svc"));

 then there is no issue again. You will see in your console two lines and both say: With Internet.

Hope this helps to fix the error. Thanks and let me know when the error is fixed.
Comment 4 Alejandro V 2011-11-01 11:06:21 UTC
I found exactly the source of the issue. Description in the last comment.
Thanks
Comment 5 Sebastien Pouliot 2011-11-16 08:50:15 UTC
We're still missing a self-contained test case so we can replicate the issue locally (see comment #2).

It's unclear if it's an IOS4-5 change or an MonoTouch 4-5 update related issue (it could be both). 

The code snippets provided in comment #3 is not clear enough (at least to me) to build a similar test case (e.g. why check for online status when the WCF call is already in progress?). A test case without WCF (or a full test case w/WCF) would help a lot to clarify the intent (and find a solution).
Comment 8 PJ 2013-07-09 02:34:18 UTC
Marking this one as RESOLVED, NO RESPONSE for now. Please feel free to re-open if you still have an issue.