【问题标题】:Problems with non-self hosted web service非自托管 Web 服务的问题
【发布时间】:2015-11-04 12:32:17
【问题描述】:

我正在尝试向非自托管的 Web 服务发出请求,换句话说:外部部分正在托管该服务并有一个开放接口。

我使用服务上的 svcutil 从 wsdl 生成了一个 C# 类: https://www.bt.bglinkws.bgonline.se/WebService/BgLinkService.svc

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    /// 



    public static void IgnoreBadCertificates()
    {
        System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
    }

    private static bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
    {
        return true;
    }

    [STAThread]
    static void Main()
    {

        Console.WriteLine("Application started");
        BgLinkServiceClient client = new BgLinkServiceClient();
        LogonRequest request = new LogonRequest();
        LogonResponse lg = new LogonResponse();


        Console.WriteLine("Attempting to connect to the Service...");
        IgnoreBadCertificates(); // Ignore certificate
        lg = client.Logon(request);

        //String autoStartToken = lg.Response.AutoStartToken;
        //Console.WriteLine("kolla");
        //Console.WriteLine(autoStartToken);


        client.Close();

    }


}
}

首先我得到了这个错误: mscorlib.dll 中出现“System.ServiceModel.Security.SecurityNegotiationException”类型的未处理异常 附加信息:无法为具有“example.com”权限的 SSL/TLS 安全通道建立信任关系。 (www 只是一个例子)

我的第一个猜测是该服务不是由受信任的证书颁发机构颁发的。

然后我从一位同事那里得到了使用 IgnoreBadCertificates 方法的提示。

之后,我尝试再次调用该请求并收到此错误: 与目标“.svc 链接”(服务链接)的“.svc 链接”(服务链接)的 SOAP 安全协商失败。有关详细信息,请参阅内部异常。”

总的来说,我对 Web 服务还很陌生,但我真的找不到解决办法。

【问题讨论】:

    标签: c# web-services wcf ssl soap


    【解决方案1】:

    假设您的绑定是正确的,可能是该服务不允许使用 SSL 3 或更早的 TLS 版本。在你的 ServicePointManager 上试试这个:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls || SecurityProtocolType.Tls11 || SecurityProtocolType.Tls12;
    

    【讨论】:

    • 我都试过了。我仍然得到目标 '.svc 链接'(服务链接)的 SOAP 安全协商与 '.svc 链接'(服务链接)失败。有关详细信息,请参阅内部异常。”
    • 那我会专注于你的绑定。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-04
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-01
    相关资源
    最近更新 更多