/// <summary /> public async Task <MethodTwoResponse> InnerRun(MethodTwoRequest request) { /* * */ var ssvc = new SampleSvcClient(); var beer = await ssvc.PingAsync(); /* * */ var outValue = -1; if (request.InValue >= 0) { var svc = new OneClient(); svc.ActivityId = this.Context.ActivityId; var t1 = svc.MethodOneAsync(new OneSvc.MethodOneRequest() { Value = request.InValue, }); var t2 = svc.MethodOneAsync(new OneSvc.MethodOneRequest() { Value = request.InValue + 5, }); /* * */ await Task.WhenAll(t1, t2); outValue = t1.Result.Value + t2.Result.Value; } /* * */ return(new MethodTwoResponse() { OutValue = outValue, OutDate = request.InDate, OutTime = request.InTime, OutDateTime = request.InDateTime, OutDuration = request.InDuration, BinaryValue = Encoding.UTF8.GetBytes("hello world"), ActivityId = this.Context.ActivityId, AccessToken = this.Context.AccessToken, ExecutionId = this.Context.ExecutionId, OutEnum = request.InEnum, }); }
public void Async() { OneClient svc = new OneClient(); svc.ActivityId = Guid.NewGuid(); svc.AccessToken = "my.jwt.token"; try { var response = svc.MethodOneAsync(new Zn.Sample.OneSvc.MethodOneRequest() { Value = 10 }).GetAwaiter().GetResult(); Assert.Fail("Expected exception."); } catch (ServiceException ex) { Assert.AreEqual("Invoke_NotJson", ex.Message); Assert.AreEqual("ZnClient.Sample", ex.Actor); } catch (Exception ex) { Assert.Fail("Expected named exception, instead got: " + ex.GetType().FullName); } }
public void MethodOn_Unhandled() { OneClient svc = new OneClient(); svc.ActivityId = Guid.NewGuid(); svc.AccessToken = "my.jwt.token"; try { svc.MethodOneAsync(new Zn.Sample.OneSvc.MethodOneRequest() { Value = 15 }).GetAwaiter().GetResult(); Assert.Fail("Expected exception."); } catch (ServiceFaultException ex) { // Zinc.WebServices.ZincException Assert.AreEqual("ZnSample.Zinc", ex.Actor); Assert.AreEqual(4006, ex.Code); // System.Exception Assert.IsTrue(ex.InnerException != null, "Expected inner exception."); Assert.IsTrue(ex.InnerException is ActorException, "Inner exception must be ActorException."); ActorException iex = (ActorException)ex.InnerException; Assert.AreEqual("ZnSample", iex.Actor); Assert.AreEqual(991, iex.Code); } catch (Exception ex) { Assert.Fail("Expected named exception, instead got: " + ex.GetType().FullName); } }
public void MethodOne_Ok() { OneClient svc = new OneClient(); svc.ActivityId = Guid.NewGuid(); svc.AccessToken = "my.jwt.token"; var response = svc.MethodOneAsync(new Zn.Sample.OneSvc.MethodOneRequest() { Value = 10 }).GetAwaiter().GetResult(); Assert.AreEqual(100, response.Value); }
/// <summary /> public static async Task MainAsync(int value, int count) { var svc = new OneClient(); svc.ActivityId = Guid.NewGuid(); Console.WriteLine("URL=" + svc.ServiceUrl); for (int i = 0; i < count; i++) { DateTime start = DateTime.UtcNow; var t1 = svc.MethodOneAsync(new OneSvc.MethodOneRequest() { Value = value, }); var t2 = svc.MethodOneAsync(new OneSvc.MethodOneRequest() { Value = value + 5, }); var t3 = svc.MethodOneAsync(new OneSvc.MethodOneRequest() { Value = value + 3, }); /* * */ try { await Task.WhenAll(t1, t2, t3); Console.Write("OK "); } catch (AggregateException ex) { if (ex.InnerExceptions.All(x => x is ServiceFaultException) == true) { Console.Write("ER "); } else { Console.Write("EX "); } } catch (ServiceFaultException) { Console.Write("ER "); } catch (Exception ex) { Console.Write("EX "); Console.WriteLine(ex.ToString()); } DateTime end = DateTime.UtcNow; TimeSpan ts = end - start; Console.WriteLine("{0} {1:000.000}ms", i, ts.TotalMilliseconds); } }