/// https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2013/201309-1/20130924-async-web-service /// /// /// <summary> /// This Method is a javascript callable method. /// </summary> /// <param name="e">A parameter from javascript.</param> /// <param name="y">A callback to javascript.</param> public void WebMethod2(data e, data_yield y) { // Send it back to the caller. var data = new data { text = "hi!" }; data.asyncyield = // we only need async // to be able to return the value // cannot await on server side just yet async state => { // Warning 2 This async method lacks 'await' operators and will run synchronously. // Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. X:\jsc.svn\examples\javascript\WebMethodXElementTransferExperiment\WebMethodXElementTransferExperiment\ApplicationWebService.cs 27 17 WebMethodXElementTransferExperiment // does the server side support async? // or do we have only one thread? // make this async! wont work yet!!! //await Task.Delay(600); Thread.Sleep(600); return new data { text = "hi from asyncyield! " + new { state.text } }; }; data.yield = (state, yy) => { // scope not shared Console.WriteLine("time to continue?"); yy( new data { text = "hi from yield! " + new { state.text } } ); }; y(data); }
public void InternalWebServiceInvoke(string yield_MethodToken, data arg0, data_yield y) { // yield_MethodToken needs security to only allow // calling public methods. // we should be encrypting them, so that client cannot tamper? Console.WriteLine("InternalWebServiceInvoke " + new { yield_MethodToken }); var yield = typeof(ApplicationWebService).Module.ResolveMethod(int.Parse(yield_MethodToken)); //Object of type 'System.Action`1[WebMethodXElementTransferExperiment.data]' cannot be converted to type 'WebMethodXElementTransferExperiment.data_yield'. // should be static! yield.Invoke(null, new object[] { arg0, y }); }