在UWP客户端上,HttpClient忽略ssl可以使用HttpBaseProtocolFilter,比如
var filter = new HttpBaseProtocolFilter();
filter.CacheControl.ReadBehavior = HttpCacheReadBehavior.MostRecent;
filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Expired);
filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted);
filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName);
Windows.Web.Http.HttpClient webhttpClient = new Windows.Web.Http.HttpClient(filter);
但是,我如何在uwp客户端上使用odata并忽略ssl?
Uri baseUri = new Uri(baseUriStr);
Container container = new Container(baseUri);
非常感谢。
答案 0 :(得分:0)
要在UWP应用中使用OData服务,我们可以使用此问题中的解决方法:How to use WCF services in Windows 10 Universal App
在UWP应用程序中添加对PCL的引用
像这样呼叫服务:
static void DisplayProduct(ClassLibrary2.ServiceReference1.Product product)
{
Debug.WriteLine("{0} {1} {2}", product.Name, product.Price, product.Category);
}
// Get an entire entity set.
static async void ListAllProducts(ClassLibrary2.ServiceReference1.Container container)
{
var dsQuery = container.Products;
var tf = new TaskFactory<IEnumerable<ClassLibrary2.ServiceReference1.Product>>();
var list = (await tf.FromAsync(dsQuery.BeginExecute(null, null),
iar => dsQuery.EndExecute(iar))).ToList();
foreach (var p in list)
{
DisplayProduct(p);
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Uri uri = new Uri("http://localhost:18441/odata");
var container = new ClassLibrary2.ServiceReference1.Container(uri);
ListAllProducts(container);
}
我按照以下文档创建了测试OData服务:Creating an OData v3 Endpoint with Web API 2
在此处查看我已完成的示例: Github Link