I'm learning to use the Rx extension for a Silverlight 4 app, which I'm working on. I have created a sample app to nail the process and I can not get it back to anything. Here's the main code:
Private IObservable & lt; Location & gt; GetGPSCoordinates (String Address 1) {var gsc = New GeocodeServiceClient ("BasicHttpBinding_IGeocodeService") as IGeocodeService; Place return location = new location (); Geodrostepense GCRPS = new godderspons (); Geocoderext gcr = new geodorify (); Gcr Credentials = new credentials (); Gcr.Credentials.ApplicationId = APP_ID2; Gcr.Query = Address1; Var myFunc = Observable.FromAsyncPattern & lt; GeocodeRequest, GeocodeResponse & gt; (Gsc.BeginGeocode, gsc.EndGeocode); GOCRPS = GOOCODRPS as MyFunk (GCR); If (GCRPS results, number> 0 & amp; amp; & amp; amp; & amp; amp; & amp; amp; & amp; amp; amp; amp; amp; amp; amp; amp; amp; ; & Amp; amp; amp; amp; amp; amp ;; gcResp. [0].} Return to the place as iObservable & lt; location & gt ;; < / Pre> gcResp comes back as a null. Any ideas or suggestions will be highly appreciated
The membership you subscribe to is asynchronous, so you do not get results immediately after subscribing You need to reach the result in the subscription.
Better yet, subscribe to all and write only the response:
Private IObservable & lt; location & Gt; GetGPSCoordinates (String Address 1) {IGeocodeService GSC = New GeocodeServiceClient ("BasicHttpBinding_IGeocodeService"); Location Return Locations = New Location (); GeocodePoint GCRPS = New GeodarSpons (); GeocodeExt GCR = New Geodicure (); Gcr Credentials = new credentials (); Gcr.Credentials.ApplicationId = APP_ID2; Gcr.Query = Address1; Var Factory = Fair. FoamSync Pattern & Lt; Geocoderequate, Geocoderns & gt; (GSCBEGCOcode, GSC & Gcode); Return Factory (GCR) Where (response => feedback resulted. Calculation & gt; 0 & amp; amp; and response. [0] result. [0] calculation> 0). Selection (reaction => response. [0]. [0]). } If you only need a valid value first (the address is unlikely to change), then add a . (1) Code> where and select . Edit: If you do not particularly want to find the address, you can return the results and have a consumer deal with it or you can return an exception And you can provide the OnError handler upon subscribing. If you are thinking of doing later, you can use the SelectMany : Return Factory (GCR). SelectionMany (response => (response.Results.Count & Gt; 0 & amp; amp; amp; and Response: Result [0]. Lections; Count & gt; 0)? Observable.Return (Results Result [0 ]. [0]: Observable.Throw & lt; location & gt; (new address notfound exception ());
Comments
Post a Comment