非自托管Web服务的问题

时间:2015-11-04 12:32:17

标签: c# web-services wcf ssl soap

我试图向非自托管的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();

    }


}
}

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

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

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

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

我对Web服务一般都很陌生,但我真的无法找到解决方案。

1 个答案:

答案 0 :(得分:0)

假设您的绑定正确,可能是该服务不允许SSL 3或更早的TLS版本。试试ServicePointManager

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