Solved

Using Rx to block asynchronous call but never calls event

Posted on 2011-03-01
2
650 Views
Last Modified: 2013-11-12
I am trying to use Rx to block for an asynchronous webclient call so that I can treat the method as synchronous.  I got the method from here:

http://www.dotnetsolutions.co.uk/blogs/markrendle/archive/2010/06/11/functional-alchemy-making-silverlight-synchronous/
and it is discussed here (but I followed the simpler above example more than this one)
http://themechanicalbride.blogspot.com/2009/07/developing-with-rx-part-2-converting.html

But it never seems to fire the event.  I can see using fiddler that the REST call is returned (with statuscode = 200 and with the expected data payload).

I am running this code in a Windows Forms application.  Does anyone have any ideas for me?  I feel like I am missing something simple here...

Thanks,
Nicole
WebClient client = new WebClient();

var blocker = Observable.FromEvent<OpenReadCompletedEventArgs>
	 (client, "OpenReadCompleted").SubscribeOnDispatcher().ToEnumerable();

string RESTGeocodeEndpoint = "http://myserver/ArcGIS/rest/services/geocode/GeocodeServer";
client.OpenReadAsync(new Uri(string.Format("{0}/findAddressCandidates?Single+Line+Input={1} {2}&Street={1}&f=json", RESTGeocodeEndpoint, street, postal)));

// Get the first element off the blocking Enumerable
var eventArgs = blocker.First().EventArgs;

//.......This next line is never called.......
if (eventArgs.Error != null)
{
	//log error
	return ;
}
else
{
//do some stuff and return
}

Open in new window

0
Comment
Question by:nicolees
  • 2
2 Comments
 

Author Comment

by:nicolees
Comment Utility
I have modified my code so that it does not require any local resources to test it.  It now hits a public test url.  Thanks for any ideas.
WebClient client = new WebClient();

var blocker = Observable.FromEvent<OpenReadCompletedEventArgs>
	 (client, "OpenReadCompleted").SubscribeOn(System.Concurrency.Scheduler.NewThread).ToEnumerable();

client.OpenReadAsync(new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Locators/ESRI_Geocode_USA/GeocodeServer/findAddressCandidates?Address=380+New+York+Street&City=Redlands&State=CA&Zip=92373"));


// Get the first element off the blocking Enumerable
var eventArgs = blocker.First().EventArgs;

//.......This next line is never called.......
if (eventArgs.Error != null)
{
	//log error
	return ;
}
else
{
//do some stuff and return
}

Open in new window

0
 

Accepted Solution

by:
nicolees earned 0 total points
Comment Utility
Okay so I think this question is irrelevant for non WPF and Silverlight applications because I can access OpenRead() instead.  I guess I just had my head too stuck in Silverlight lately.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video discusses moving either the default database or any database to a new volume.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now