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


C# JsonServiceClient.PostFileWithRequest方法代码示例

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


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

示例1: btnTest_Click

        private async void btnTest_Click(object sender, RoutedEventArgs e)
        {
            //Make all access to UI components in UI Thread, i.e. before entering bg thread.
            var name = txtName.Text;
            ThreadPool.QueueUserWorkItem(_ =>
            {
                try
                {
                    var client = new JsonServiceClient("http://localhost:2000/")
                    {
                        //this tries to access UI component which is invalid in bg thread
                        ShareCookiesWithBrowser = false
                    };
                    var fileStream = new MemoryStream("content body".ToUtf8Bytes());
                    var response = client.PostFileWithRequest<UploadFileResponse>(
                        fileStream, "file.txt", new UploadFile { Name = name });

                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        lblResults.Content = "File Size: {0} bytes".Fmt(response.FileSize);
                    });
                }
                catch (Exception ex)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        lblResults.Content = ex.ToString();
                    });
                }
            });
        }
开发者ID:phaufe,项目名称:HelloMobile,代码行数:31,代码来源:MainPage.xaml.cs

示例2: Deploy

            public bool Deploy(ZipPackage package, ILog logger)
            {
                var options = package.GetPackageOptions<WebOptions>();

                logger.Info("Deploying iis package to {0}:{1} using {2}".Fmt(options.WebsiteName, options.WebsitePort, options.DeployService));

                var client = new JsonServiceClient(options.DeployService); // todo
                var request = new TriggerDeployment()
                {
                    AppPoolName = "ZZZ_Integration_PoolName",
                    AppPoolUser = "JackBauer",
                    AppPoolPassword = "topsecret",
                    WebsiteName = "ZZZ_Integration_Website_Simple",
                    AppRoot = "/",
                    PackageId = "IntegrationTest",
                    PackageVersion = "1.3.3.7",
                    WebsitePhysicalPath = @"C:\temp\integrationtests",
                    RuntimeVersion = RuntimeVersion.Version40,
                };

                var response = client.PostFileWithRequest<TriggerDeploymentResponse>("/deployments", new FileInfo("package.zip"), request);

                return true;
            }
开发者ID:tobiaszuercher,项目名称:PowerDeploy,代码行数:24,代码来源:WebDeployment.cs

示例3: Can_POST_upload_file_using_ServiceClient_with_request_and_QueryString

        public void Can_POST_upload_file_using_ServiceClient_with_request_and_QueryString()
        {
            IServiceClient client = new JsonServiceClient(Config.ServiceStackBaseUri);

            var uploadFile = new FileInfo("~/TestExistingDir/upload.html".MapHostAbsolutePath());

            var request = new FileUpload();
            var response = client.PostFileWithRequest<FileUploadResponse>(
                Config.ServiceStackBaseUri + "/fileuploads?CustomerId=123&CustomerName=Foo,Bar", 
                uploadFile, request);

            var expectedContents = new StreamReader(uploadFile.OpenRead()).ReadToEnd();
            Assert.That(response.Name, Is.EqualTo("upload"));
            Assert.That(response.FileName, Is.EqualTo(uploadFile.Name));
            Assert.That(response.ContentLength, Is.EqualTo(uploadFile.Length));
            Assert.That(response.Contents, Is.EqualTo(expectedContents));
            Assert.That(response.CustomerName, Is.EqualTo("Foo,Bar"));
            Assert.That(response.CustomerId, Is.EqualTo(123));
        }
开发者ID:calebjenkins,项目名称:ServiceStack,代码行数:19,代码来源:FileUploadTests.cs

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