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


C# HttpClient.CreateQuery方法代码示例

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


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

示例1: AsynchronousExecution

        public void AsynchronousExecution()
        {
            HttpClient client = new HttpClient(address);
            var customers = client.CreateQuery<Customer>("Customers");

            // EndX method
            customers.ExecuteAsync().ContinueWith(t => Assert.AreEqual(5, t.Result.Count()));

            var q =
                from customer in customers
                where customer.Id > 4
                select customer;

            customers = ((WebQuery<Customer>)q);
            // Callback
            customers.ExecuteAsync().ContinueWith(t=>Callback(t.Result));
            mre.WaitOne();
        }
开发者ID:AlexZeitler,项目名称:WcfHttpMvcFormsAuth,代码行数:18,代码来源:QueryServiceScenarioTests.cs

示例2: Basic

        public void Basic()
        {
            foreach (var baseAddress in baseAddresses)
            {
                HttpClient client = new HttpClient(baseAddress);
                client.Channel = new WebRequestChannel();

                HttpClient client2 = new HttpClient(new Uri(baseAddress));
                client2.Channel = new WebRequestChannel();

                foreach (var relativeAddress in resourceAddresses)
                {
                    WebQuery<Customer> q = client.CreateQuery<Customer>(relativeAddress);
                    WebQuery<Customer> q2 = client2.CreateQuery<Customer>(new Uri(relativeAddress, UriKind.Relative));
                    string s = q.RequestUri.AbsoluteUri;
                    string s2 = q2.RequestUri.AbsoluteUri;

                    Assert.AreEqual(s, s2);
                }
            }
        }
开发者ID:AlexZeitler,项目名称:WcfHttpMvcFormsAuth,代码行数:21,代码来源:QueryCreationTests.cs

示例3: NestedQueryTest

        public void NestedQueryTest()
        {
            HttpClient client = new HttpClient(address);
            var customers = client.CreateQuery<Customer>("Customers");

            var customersNested = (WebQuery<Customer>)
                customers.Where(customer => customer.Id > customers.Skip(2).First().Id);

            Assert.AreEqual(2, customersNested.ToList().Count());
        }
开发者ID:AlexZeitler,项目名称:WcfHttpMvcFormsAuth,代码行数:10,代码来源:QueryServiceScenarioTests.cs

示例4: TestMockFailedComposer2

 public void TestMockFailedComposer2()
 {
     HttpClient client = new HttpClient(address2);
     var customers = client.CreateQuery<Customer>("Failed");
     customers.Execute();
 }
开发者ID:AlexZeitler,项目名称:WcfHttpMvcFormsAuth,代码行数:6,代码来源:QueryServiceScenarioTests.cs

示例5: SynchronousExecution2

        public void SynchronousExecution2()
        {
            HttpClient client = new HttpClient(address2);
            var customers = client.CreateQuery<Customer>("Customers");
            Console.WriteLine("All customers using XML deserialization");
            PrintCustomers(customers);
            Assert.AreEqual(5, customers.ToList().Count());

            var customersJson = client.CreateQuery<Customer>("CustomersJson");
            Console.WriteLine("All customers using JSON deserialization");
            PrintCustomers(customersJson);
            Assert.AreEqual(5, customers.ToList().Count());

            var customersWildcard = client.CreateQuery<Customer>("");
            Console.WriteLine("Customers returned by wildcard method");
            PrintCustomers(customersWildcard);
            Assert.AreEqual(5, customers.ToList().Count());

            Console.WriteLine("All customers whose id > 4");
            var q =
                from customer in customers
                where customer.Id > 4
                select customer;
            Assert.AreEqual(1, q.ToList().Count());
            Assert.AreEqual(1, q.ToList().Count());

            var results = ((WebQuery<Customer>)q).Execute();
            Assert.AreEqual(1, results.ToList().Count());

            var customersNone = client.CreateQuery<Customer>("CustomersNone");
            Assert.AreEqual(1, results.ToList().Count());
        }
开发者ID:AlexZeitler,项目名称:WcfHttpMvcFormsAuth,代码行数:32,代码来源:QueryServiceScenarioTests.cs

示例6: SingleElementOperations2

        public void SingleElementOperations2()
        {
            HttpClient client = new HttpClient(address2);
            var customers = client.CreateQuery<Customer>("Customers");

            Assert.AreEqual("LastName1", customers.First().Name);
            Assert.AreEqual("LastName1", customers.Take(1).Single().Name);
        }
开发者ID:AlexZeitler,项目名称:WcfHttpMvcFormsAuth,代码行数:8,代码来源:QueryServiceScenarioTests.cs

示例7: EmptyQuery

 public void EmptyQuery()
 {
     HttpClient client = new HttpClient(baseAddresses[0]);
     WebQuery<Customer> emptyQuery = client.CreateQuery<Customer>();
     Console.WriteLine("Empty query resource at: {0}", emptyQuery.RequestUri.AbsoluteUri);
 }
开发者ID:AlexZeitler,项目名称:WcfHttpMvcFormsAuth,代码行数:6,代码来源:QueryCreationTests.cs


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