public void SynchronousClientExperiment() { TraceLine(Instructions.WaitForCompletion); // ExampleServiceClient is auto-generated by Visual Studio. using (var client = new ExampleServiceClient( new BasicHttpBinding(), new EndpointAddress(serviceUrl))) { var results = client.GetHttpResponses(new[] { new Uri("http://microsoft.com"), new Uri("http://codeplex.com"), new Uri("http://google.com"), new Uri("http://wikipedia.org") }); foreach (var result in results) { TraceLine(); TraceSuccess(result.Url.ToString()); TraceLine(result.ResponseSummary); } } }
public void AsynchronousClientExperiment() { TraceLine(Instructions.PressAnyKeyToCancel); TraceLine(); // ExampleServiceClient is auto-generated by Visual Studio. using (var client = new ExampleServiceClient( new BasicHttpBinding(), new EndpointAddress(serviceUrl))) { #if WINDOWS_PHONE var invokeAsync = Observable.FromAsyncPattern <Uri[], ExampleServiceResponseReference>( client.BeginGetSlowestHttpResponse, client.EndGetSlowestHttpResponse); var observable = invokeAsync(new[] { new Uri("http://microsoft.com"), new Uri("http://codeplex.com"), new Uri("http://google.com"), new Uri("http://wikipedia.org") }); #else var observable = Task.Factory.FromAsync <Uri[], ExampleServiceResponseReference>( client.BeginGetSlowestHttpResponse, client.EndGetSlowestHttpResponse, new[] { new Uri("http://microsoft.com"), new Uri("http://codeplex.com"), new Uri("http://google.com"), new Uri("http://wikipedia.org") }, state: null) .ToObservable(); #endif using (observable.Subscribe( result => { TraceSuccess(result.Url.ToString()); TraceLine(result.ResponseSummary); TraceLine(); }, ConsoleOutputOnError(), ConsoleOutputOnCompleted())) { WaitForKey(); } } }