当前位置: 首页>>代码示例>>C#>>正文


C# JsonServiceClient.PostAsync方法代码示例

本文整理汇总了C#中JsonServiceClient.PostAsync方法的典型用法代码示例。如果您正苦于以下问题:C# JsonServiceClient.PostAsync方法的具体用法?C# JsonServiceClient.PostAsync怎么用?C# JsonServiceClient.PostAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonServiceClient的用法示例。


在下文中一共展示了JsonServiceClient.PostAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            int amount = -1;
            JsonServiceClient client = null;
            client = new JsonServiceClient("http://localhost:4057") { UserName = "jsuser", Password = "password1" };
            var assignRResp = client.Send<AssignRolesResponse>(new AssignRoles
            {
                UserName = "jsuser",
                Roles = new ArrayOfString("StatusUser"),
                Permissions = new ArrayOfString("GetStatus")
            });

            try
            {
                var repsspp = client.Send<StatusResponse>(new StatusQuery() { Date = DateTime.Now });
            }
            catch (WebServiceException ex)
            {
                if (ex.Message != null) { }
            }

            client.PostAsync<MagicResponse>(new MagicRequest { Id = 1 },
                resp => Console.WriteLine(resp.OutId), (resp, err) => { Console.WriteLine(err.Message); });

            while (amount != 0)
            {
                Console.WriteLine("Enter a protein amount (press 0 to exit)");
                if (int.TryParse(Console.ReadLine(), out amount))
                {
                    var response = client.Send<EntryResponse>(new Entry { Amount = amount, Time = DateTime.Now });
                    Console.WriteLine("Response, ID: " + response.Id);
                }
            }

            var reps2 = client.Post<StatusResponse>("status", new StatusQuery { Date = DateTime.Now });
            Console.WriteLine("{0} / {1}", reps2.Total, reps2.Goal);
            Console.WriteLine(reps2.Message);
            Console.ReadLine();
        }
开发者ID:OleksandrKulchytskyi,项目名称:NServiceStack-Test,代码行数:39,代码来源:Program.cs

示例2: btnAuth_Click

        private async void btnAuth_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var client = new JsonServiceClient("http://localhost:81/");

                await client.PostAsync(new Authenticate
                {
                    provider = "credentials",
                    UserName = "user",
                    Password = "pass",
                });

                var response = await client.GetAsync(new HelloAuth { Name = "secure" });

                lblResults.Content = response.Result;
            }
            catch (Exception ex)
            {
                lblResults.Content = ex.ToString();
            }
        }
开发者ID:GDBSD,项目名称:ServiceStack,代码行数:22,代码来源:MainPage.xaml.cs

示例3: OnCreate

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            //AndroidPclExportClient.Configure();

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var btnSync = FindViewById<Button>(Resource.Id.btnSync);
            var btnAsync = FindViewById<Button>(Resource.Id.btnAsync);
            var btnAwait = FindViewById<Button>(Resource.Id.btnAwait);
            var btnAuth = FindViewById<Button>(Resource.Id.btnAuth);
            var btnShared = FindViewById<Button>(Resource.Id.btnShared);
            var txtName = FindViewById<EditText>(Resource.Id.txtName);
            var lblResults = FindViewById<TextView>(Resource.Id.lblResults);

            //10.0.2.2 = loopback
            //http://developer.android.com/tools/devices/emulator.html
            var client = new JsonServiceClient("http://10.0.2.2:2000/");
            var gateway = new SharedGateway("http://10.0.2.2:2000/");

            btnSync.Click += delegate
            {
                try
                {
                    var response = client.Get(new Hello { Name = txtName.Text });
                    lblResults.Text = response.Result;

                    using (var ms = new MemoryStream("Contents".ToUtf8Bytes()))
                    {
                        ms.Position = 0;
                        var fileResponse = client.PostFileWithRequest<HelloResponse>(
                            "/hello", ms, "filename.txt", new Hello { Name = txtName.Text });

                        lblResults.Text = fileResponse.Result;
                    }
                }
                catch (Exception ex)
                {
                    lblResults.Text = ex.ToString();
                }
            };

            btnAsync.Click += delegate
            {
                client.GetAsync(new Hello { Name = txtName.Text })
                    .Success(response => lblResults.Text = response.Result)
                    .Error(ex => lblResults.Text = ex.ToString());
            };

            btnAwait.Click += async delegate
            {
                try
                {
                    var response = await client.GetAsync(new Hello { Name = txtName.Text });
                    lblResults.Text = response.Result;
                }
                catch (Exception ex)
                {
                    lblResults.Text = ex.ToString();
                }
            };

            btnAuth.Click += async delegate
            {
                try
                {
                    await client.PostAsync(new Authenticate
                    {
                        provider = "credentials",
                        UserName = "user",
                        Password = "pass",
                    });

                    var response = await client.GetAsync(new HelloAuth { Name = "Secure " + txtName.Text });

                    lblResults.Text = response.Result;
                }
                catch (Exception ex)
                {
                    lblResults.Text = ex.ToString();
                }
            };

            btnShared.Click += async delegate
            {
                try
                {
                    var greeting = await gateway.SayHello(txtName.Text);
                    lblResults.Text = greeting;
                }
                catch (Exception ex)
                {
                    lblResults.Text = ex.ToString();
                }
            };
        }
开发者ID:phaufe,项目名称:HelloMobile,代码行数:97,代码来源:Activity1.cs


注:本文中的JsonServiceClient.PostAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。