Skip to main content
 首页 » 编程设计

c#之“https”无效;预计 'http'

2024年02月13日14tuyile006

我一直在尝试向 https://americas-uapi.copy-webservices.travelport.com/B2BGateway/connect/uAPI/SystemService 发送 ping 请求但我收到以下错误: 发出 ping 请求时出错:提供的 URI 方案“https”无效;应为“http”。

提供给我的端点使用 https。我该如何纠正这个错误?

这是我的 web.config

<?xml version="1.0"?> 
 <configuration> 
<system.web> 
  <compilation debug="true" targetFramework="4.5" /> 
  <httpRuntime targetFramework="4.5" /> 
</system.web> 
 
<system.serviceModel> 
    <bindings> 
        <basicHttpBinding> 
            <binding name="ExternalCacheAccessBinding" /> 
            <binding name="SystemPingBinding" /> 
            <binding name="SystemInfoBinding" /> 
            <binding name="SystemTimeBinding" /> 
        </basicHttpBinding> 
    </bindings> 
    <client> 
        <endpoint address="https://americas-uapi.copy-webservices.travelport.com/B2BGateway/connect/uAPI/SystemService" 
            binding="basicHttpBinding" bindingConfiguration="ExternalCacheAccessBinding" 
            contract="WSDLService.ExternalCacheAccessPortType" name="ExternalCacheAccessPort" /> 
        <endpoint address="https://americas-uapi.copy-webservices.travelport.com/B2BGateway/connect/uAPI/SystemService" 
            binding="basicHttpBinding" bindingConfiguration="SystemPingBinding" 
            contract="WSDLService.SystemPingPortType" name="SystemPingPort" /> 
        <endpoint address="https://americas-uapi.copy-webservices.travelport.com/B2BGateway/connect/uAPI/SystemService" 
            binding="basicHttpBinding" bindingConfiguration="SystemInfoBinding" 
            contract="WSDLService.SystemInfoPortType" name="SystemInfoPort" /> 
        <endpoint address="https://americas-uapi.copy-webservices.travelport.com/B2BGateway/connect/uAPI/SystemService" 
            binding="basicHttpBinding" bindingConfiguration="SystemTimeBinding" 
            contract="WSDLService.SystemTimePortType" name="SystemtimePort" /> 
    </client> 
</system.serviceModel> 

这是我按照教程发送的请求:

// PING REQUEST 
    // 
 
    String payload= "this my payload; there are many like it but this one is mine"; 
    String someTraceId = "doesntmatter-8176"; 
 
    //set up the request parameters into a PingReq object 
    PingReq req = new PingReq(); 
    PingRsp rsp = new PingRsp(); 
    req.Payload=payload; 
    req.TraceId=someTraceId; 
    SystemPingPortTypeClient port = new SystemPingPortTypeClient(); 
    try { 
        //run the ping request 
        UserNamePasswordClientCredential creds = port.ClientCredentials.UserName; 
        creds.UserName = "MyUserName"; 
        creds.Password = "MyPassword"; 
 
        rsp = port.service(req); 
        //print results.. payload and trace ID are echoed back in response 
        Label1.Text = rsp.Payload; 
        Label2.Text = rsp.TraceId; 
        Label3.Text = rsp.TransactionId; 
        }  
    catch (Exception ex) { 
    //usually only the error message is useful, not the full stack 
    //trace, since the stack trace in is your address space... 
    Label1.Text = "Error making ping request: " + ex.Message; 

请您参考如下方法:

<security mode="Transport"> in Servicereference.ClientConfig file 

Here

Check here too

更新:根据您的意见:

 <bindings> 
   <basicHttpBinding> 
   <security mode="Transport">