Solved

Using Rx to block asynchronous call but never calls event

Posted on 2011-03-01
2
662 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 

Author Comment

by:nicolees
ID: 35018512
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
ID: 35018559
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

635 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