本文整理汇总了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();
}
示例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);
}
}
}
示例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());
}
示例4: TestMockFailedComposer2
public void TestMockFailedComposer2()
{
HttpClient client = new HttpClient(address2);
var customers = client.CreateQuery<Customer>("Failed");
customers.Execute();
}
示例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());
}
示例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);
}
示例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);
}