首页 > 解决方案 > ASP.NET Core 2.2 中面临的问题“提供的 URI 方案 'https' 无效;应为 'http'。\r\n参数名称:通过”

问题描述

在 asp.net core 2.2 中使用 Galileo Flight UAPI API 时出错。调用异步方法时出现一个错误

提供的 URI 方案“https”无效;预期的“http”。参数名称:via

我已根据 .net 核心要求更新了 lib 并更改了 BasicHttpBinding

我已经根据搜索 google 和 Stackoverflow 更改了代理

private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
{
    if ((endpointConfiguration == EndpointConfiguration.AirLowFareSearchPort))
    {
        System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
        result.MaxBufferSize = int.MaxValue;
        result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
        result.MaxReceivedMessageSize = int.MaxValue;
        result.AllowCookies = true;
        result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
        result.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Ntlm;
        result.TransferMode = System.ServiceModel.TransferMode.Buffered;
        return result;
    }
    throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
AirLowFareSearchPortTypeClient client = 
    new AirLowFareSearchPortTypeClient(AirLowFareSearchPortTypeClient.EndpointConfiguration.AirLowFareSearchPort, uRL + "/AirService");

client.ClientCredentials.UserName.UserName = username;
client.ClientCredentials.UserName.Password = password;

 var httpHeaders = Helper.ReturnHttpHeader(username, password);
client.Endpoint.EndpointBehaviors.Add(new HttpHeadersEndpointBehavior(httpHeaders));
SessionContext context = new SessionContext();
var serviceResponse = await client.serviceAsync(context, lowFareSearchReq);

标签: c#asp.net-core-webapiasp.net-core-2.2

解决方案


创建自己的 BasicHttpBinding 对象并设置“Transport”Security.Mode 和其他属性,分配给 PortType 客户端。这是代码。

 System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding();
binding.MaxBufferSize = int.MaxValue;
binding.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
binding.MaxReceivedMessageSize = int.MaxValue;
binding.AllowCookies = true;
binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
binding.TransferMode = System.ServiceModel.TransferMode.Buffered;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
var endpoint = new EndpointAddress(uRL + "/AirService");
//AirLowFareSearchPortTypeClient client = new AirLowFareSearchPortTypeClient(AirLowFareSearchPortTypeClient.EndpointConfiguration.AirLowFareSearchPort, uRL + "/AirService");
AirLowFareSearchPortTypeClient client = new AirLowFareSearchPortTypeClient(binding, endpoint);

推荐阅读