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

时间:2019-07-02 11:29:09

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

在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);

1 个答案:

答案 0 :(得分:0)

创建自己的BasicHttpBinding对象并设置“传输” 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);