Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 这就是WCF SSL安全通道出现故障的原因吗?_C#_Wcf_Ssl - Fatal编程技术网

C# 这就是WCF SSL安全通道出现故障的原因吗?

C# 这就是WCF SSL安全通道出现故障的原因吗?,c#,wcf,ssl,C#,Wcf,Ssl,我正在支持一个项目,我们最近需要将一系列升级应用到更新版本的.Net Framework。这在很大程度上是成功的,但最后一个组件已经存在很长时间了 我们的客户端使用InfoPath模板填充信息,供其他用户使用。模板所需的一切都来自我们托管的WCF web服务。我们使用以下代码设置web服务调用 private WSHttpBinding CreateBinding() { var wsHttpBinding = new WSHttpBinding();

我正在支持一个项目,我们最近需要将一系列升级应用到更新版本的.Net Framework。这在很大程度上是成功的,但最后一个组件已经存在很长时间了

我们的客户端使用InfoPath模板填充信息,供其他用户使用。模板所需的一切都来自我们托管的WCF web服务。我们使用以下代码设置web服务调用

    private WSHttpBinding CreateBinding()
    {
        var wsHttpBinding = new WSHttpBinding();
        wsHttpBinding.CloseTimeout = TimeSpan.FromMinutes(10);
        wsHttpBinding.OpenTimeout = TimeSpan.FromMinutes(10);
        wsHttpBinding.ReceiveTimeout = TimeSpan.FromMinutes(10);
        wsHttpBinding.SendTimeout = TimeSpan.FromMinutes(10);
        wsHttpBinding.BypassProxyOnLocal = false;
        wsHttpBinding.TransactionFlow = false;
        wsHttpBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
        wsHttpBinding.MaxBufferPoolSize = 524288;
        wsHttpBinding.MaxReceivedMessageSize = 2147483647;
        wsHttpBinding.MessageEncoding = WSMessageEncoding.Text;
        wsHttpBinding.TextEncoding = Encoding.UTF8;
        wsHttpBinding.UseDefaultWebProxy = true;
        wsHttpBinding.AllowCookies = false;
        wsHttpBinding.ReaderQuotas.MaxDepth = 32;
        wsHttpBinding.ReaderQuotas.MaxStringContentLength = 2147483647;
        wsHttpBinding.ReaderQuotas.MaxArrayLength = 16384;
        wsHttpBinding.ReaderQuotas.MaxBytesPerRead = 4096;
        wsHttpBinding.ReaderQuotas.MaxNameTableCharCount = 16384;
        wsHttpBinding.ReliableSession.Ordered = true;
        wsHttpBinding.ReliableSession.InactivityTimeout = TimeSpan.FromMinutes(10);
        wsHttpBinding.ReliableSession.Enabled = false;

        wsHttpBinding.Security.Mode = SecurityMode.TransportWithMessageCredential;
        wsHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
        wsHttpBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
        wsHttpBinding.Security.Transport.Realm = string.Empty;
        wsHttpBinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
        wsHttpBinding.Security.Message.NegotiateServiceCredential = false;
        wsHttpBinding.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Basic256;

        return wsHttpBinding;

    }

    private EndpointAddress CreateEndPoint()
    {
        X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
        store.Open(OpenFlags.ReadOnly);
        X509Certificate2 certificate = store.Certificates.Find(X509FindType.FindBySubjectName, "*.wildcard.address.foo", false)[0];
        store.Close();

        EndpointIdentity identity = EndpointIdentity.CreateX509CertificateIdentity(certificate);

        string address = getWcfServiceUrl();

        AddressHeader header = AddressHeader.CreateAddressHeader(address);
        List<AddressHeader> headerList = new List<AddressHeader> { header };
        Uri uri = new Uri(address); 
        var endpointAddress = new EndpointAddress(uri, identity, headerList.ToArray());
        return endpointAddress;
    }
}
在这种情况下,将返回以下错误:

请求被中止:无法创建SSL/TLS安全通道

我的怀疑是,我们正在围绕本地客户端(即InfoPath)和web服务之间的SSL连接设置一组非常特定的约束,但从该web服务到第三方的调用除了通过HTTPS调用之外,没有设置任何约束


在试图解决此问题时,我应该注意什么?

WCF IMHO对两端的配置都很挑剔,并在前后特别要求传输凭据之类的东西。我怀疑您无法控制如何在第三方管理安全性,也无法更改它,但您调用所有web服务的通用方法将无法工作,因为配置不匹配。

其他有用信息:我们可以使用Fiddler通过SSL直接成功调用第三方。响应头中没有明确指示第三方正在使用的协议。
    private string requestURL(string url)
    {
        string toReturn = null;
        Stream stream = null;
        try
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = httpMethod;
            stream = ((HttpWebResponse)request.GetResponse()).GetResponseStream();
            StreamReader reader = new StreamReader(stream);
            toReturn = reader.ReadToEnd();
        }
        catch(Exception e)
        {
            throw new Exception("Error with that service please try again: " + e.Message, e);
        }
        finally
        {
            if(stream != null)
            {
                stream.Close();
            }
        }
        return toReturn;
    }