I have written a simplified Silverlight client library to use RCs for my WCF web service, but I think that sometimes- Sometimes I am missing the events of completion.
Public IObservable & lt; XElement & gt; GetReport (string report name) {Observable.FromEvent & lt; GetReportDataCompletedEventArgs & gt; (Client, "Return to Clients" in Observable.ToAsync & lt; String & gt; (client.GetReportDataAsync) (reportName) from Observable.Return (New WebServiceClient ()) in result in GetReportDataCompleted. Take closer (1) in this. Select the close client (customer) result. EventArgs.Result; }
I believe that this issue is due to the fact that the web service is called and gets the returns before subscribing to the full event. I can not understand how to get an RX to subscribe to the event before anchak call. I tried StartWith, but for this input and output type are the same, any ideas are needed?
It seems the best answer is Observable.CreateWithDisposable ()
Example To use
public IObservable & lt; XElement & gt; GetReport (String ReportsName) {Return to the Observaval.Righton in Cloud (New WebSewiceClient ()) is complete in the overview. CreateWithDisposable & lt; GetReportDataCompletedEventArgs & gt; (Supervisor = & gt; {var subscription = Observable.FromEvent & lt; GetReportDataCompletedEventArgs & gt; (Client, "GetReportDataCompleted"). (1) Select (E = & gt; E.A.A.G. Argus). Subscribe (Supervisor); Customer.GateReverportDataSynx (ReportName); Return Subscription;}) Out of this Clause (client) selection is complete result; }
To make it easier to work with, I re-create CreateWithDisposable in a normal function which can be used with my web service call, in which event args type event Name is automatically determined by:
Private IObservable & lt; T & gt; CallService & lt; T & gt; (ICommunicationObject service client, start action) where T: AsyncCompletedEventArgs {if (typeof (T) == type (AsyncCompletedEventArgs)) {new InvalidOperationException ("The argument type of event can not be used to determine the name of the event, Use Event Name Overload instead. "); } String Full EventName = typeof (T) .name. Trim ("EventArgs"); Return CallService & lt; T & gt; (ServiceClient, Startup, Complete EventName); } Private IObservable & lt; T & gt; Callersia & lt; T & gt; (ICommunicationObject Service Client, Action Start, String Full EventName) where T: AsyncCompletedEventArgs {Return Observable.CreateWithDisposable & gt; T & gt; (Supervisor = & gt; {var subscription = Observable.FromEvent & lt; T & gt; (serviceClient, completedEventName).). Choose (E = & gt; E.A.A.A.G. Subscribe (supervisor); Start (); Return membership;}); } // Example Usage: Public IObservable & lt; XElement & gt; GetReport (String ReportsName) {Return to the cloud in the cloud. Ryan (WebServiceClient () in this new) has been completed. CallService & lt; GetReportDataCompletedEventArgs & gt; (Client, () = & gt; client.GetReportDataAsync (reportName)) Close this off. Select CloseClient (Customer). result; } /// & lt; Summary & gt; /// Asynchronous Web Service Closes Clients /// & lt; / Summary & gt; /// & lt; Param name = "client" & gt; The web service client will be closed. & Lt; / Param & gt; /// & lt; Returns & gt; A single success gives a cold-viewable sequence of the unit. & Lt; / Returns & gt; Private IObservable & lt; AsyncCompletedEventArgs & gt; CloseClient (WebServiceClient Client) {return.CallService & lt; AsyncCompletedEventArgs & gt; (Client, client.CloseAynync, "Closed End"); }
Hope this helps someone else!
Comments
Post a Comment