Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 666
  • Last Modified:

Using Rx to block asynchronous call but never calls event

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
nicolees
Asked:
nicolees
  • 2
1 Solution
 
nicoleesAuthor Commented:
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
 
nicoleesAuthor Commented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now