【问题标题】:Fedex API using c# get rates for freight, why am I getting an errorFedex API 使用 c# 获取运费,为什么会出现错误
【发布时间】:2019-08-05 20:16:08
【问题描述】:

我从 Fedex 网站下载了示例代码,以便调用 api 以获取特定运费的费率。该程序是 RateWebServiceClient。

我创建了测试凭据并输入了测试密钥、密码、帐号和仪表编号。服务网址是https://wsbeta.fedex.com:443/web-services/rate。当我通过传入 RateRequest 对象调用 service.GetRates 时,出现以下异常:

底层连接已关闭:发送时发生意外错误。 从传输流中接收到意外的 EOF 或 0 字节。

然后我创建了生产凭据并更改了密钥、密码、帐号和仪表编号,并将服务 URL 更改为 https://ws.fedex.com:443/web-services/rate。现在我得到以下 SoapException:

RateRequest 错误的 UnrecoverableClientErrorSchemaErrorvalidation 失败:cvc-elt.1:找不到元素“RateRequest”的声明。

我不确定我错过了什么,或者我是否可能调用了不正确的 Web 服务 url 或其他东西。

【问题讨论】:

    标签: c# api fedex


    【解决方案1】:

    我不得不在 C# 中使用这样做:

    using System.Security.Authentication;
    

    创建 2 个常量:

    public const SslProtocols _Tls12 = (SslProtocols)0x00000C00;
    public const SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12;
    

    这样使用:

    ServicePointManager.SecurityProtocol = Tls12;
    

    【讨论】:

      【解决方案2】:

      在 C# 中,

      using System.Web.Services.Protocols;
      using System.Net;
      
      ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
      

      【讨论】:

        猜你喜欢
        • 2023-03-31
        • 2023-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多