SslStreamSecurityBindingElement 類別

定義

表示以 SSL 資料流支援通道安全性的自訂繫結項目。

public ref class SslStreamSecurityBindingElement : System::ServiceModel::Channels::BindingElement
public ref class SslStreamSecurityBindingElement : System::ServiceModel::Channels::StreamUpgradeBindingElement
public ref class SslStreamSecurityBindingElement : System::ServiceModel::Channels::StreamUpgradeBindingElement, System::ServiceModel::Channels::ITransportTokenAssertionProvider, System::ServiceModel::Description::IPolicyExportExtension
public class SslStreamSecurityBindingElement : System.ServiceModel.Channels.BindingElement
public class SslStreamSecurityBindingElement : System.ServiceModel.Channels.StreamUpgradeBindingElement
public class SslStreamSecurityBindingElement : System.ServiceModel.Channels.StreamUpgradeBindingElement, System.ServiceModel.Channels.ITransportTokenAssertionProvider, System.ServiceModel.Description.IPolicyExportExtension
type SslStreamSecurityBindingElement = class
    inherit BindingElement
type SslStreamSecurityBindingElement = class
    inherit StreamUpgradeBindingElement
type SslStreamSecurityBindingElement = class
    inherit StreamUpgradeBindingElement
    interface ITransportTokenAssertionProvider
    interface IPolicyExportExtension
Public Class SslStreamSecurityBindingElement
Inherits BindingElement
Public Class SslStreamSecurityBindingElement
Inherits StreamUpgradeBindingElement
Public Class SslStreamSecurityBindingElement
Inherits StreamUpgradeBindingElement
Implements IPolicyExportExtension, ITransportTokenAssertionProvider
繼承
SslStreamSecurityBindingElement
繼承
SslStreamSecurityBindingElement
實作

備註

TCP 和具名管道這類使用資料流導向通訊協定的傳輸,支援資料流傳輸升級。 具體而言,Windows Communication Foundation (WCF) 提供安全性升級。 此傳輸安全性的組態是由此類別和 SslStreamSecurityBindingElement 所封裝,對此您可加以設定並新增至自訂繫結。 除此之外,協力廠商可撰寫其自訂 StreamSecurityBindingElement。 這些繫結項目會針對建置用戶端和伺服器的資料流升級提供者所呼叫的 StreamUpgradeBindingElement 類別加以擴充。

自訂繫結包含以特定順序排列的繫結項目之集合:第一個會新增代表繫結堆疊頂端的項目,第二個新增繫結堆疊中次一項目,依此類推。

若要將這個類別加入至繫結

  1. 建立 BindingElementCollection

  2. 建立在繫結堆疊中位於此繫結項目上方的自訂繫結項目,例如選擇性的 TransactionFlowBindingElementReliableSessionBindingElement

  3. 依先前所述的順序,使用 BindingElementCollection 方法將這些建立的項目加入至 InsertItem

  4. 建立 SslStreamSecurityBindingElement 的執行個體,並將它新增至集合。

  5. 將其他任何自訂繫結項目新增至集合中,例如 TcpTransportBindingElement

在匯入 WSDL 之後,您必須在用戶端端點上手動指定正確的 UPN/SPN,或在用戶端 SslStreamSecurityBindingElement 的 上指定自訂 IdentityVerifier

  1. WSDL 中不會發行任何服務識別, 而會使用 SspiNegotiatedOverTransport 和 HTTPS (例如 SecurityMode = WSHttpBindingTransportWithMessageCredential)。 如果執行中的服務沒有機器識別,匯入 WSDL 後,您必須在用戶端端點上手動指定正確 UPN/SPN。

  2. DNS 服務識別會在 WSDL 中發佈。 SspiNegotiatedOverTransport例如, NetTcpBinding 搭配 SecurityMode = TransportWithMessageCredential) 而非 UPN/SPN, (使用 和 SslStreamSecurityBindingElement 。 如果執行中的服務沒有機器識別,或者 DNS 識別並非機器的識別,匯入 WSDL 後,您必須在用戶端端點上手動指定正確 UPN/SPN。

  3. WSDL 中發行的 DNS 識別。 如果用戶端覆寫了 SslStreamSecurityBindingElement,您必須在用戶端的 IdentityVerifier 上指定自訂的 SslStreamSecurityBindingElement

下列程式碼示範如何在用戶端端點上手動指定正確的 UPN/SPN,以及如何在用戶端的 IdentityVerifier 上指定自訂的 SslStreamSecurityBindingElement

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Net;  
using System.IdentityModel.Claims;  
using System.IdentityModel.Policy;  
using System.Security.Cryptography.X509Certificates;  
using System.ServiceModel;  
using System.ServiceModel.Channels;  
using System.ServiceModel.Description;  
using System.ServiceModel.Security;  
using System.Xml;  

namespace ServiceNamespace  
{  
    [ServiceContract]  
    interface IService  
    {  
        [OperationContract]  
        void DoSomething();  
    }  

    class DnsIdentityVerifier : IdentityVerifier  
    {  
        DnsEndpointIdentity _expectedIdentity;  

        public DnsIdentityVerifier(EndpointAddress serviceEndpoint)  
        {  
            _expectedIdentity = new DnsEndpointIdentity(serviceEndpoint.Uri.DnsSafeHost);  
        }  

        public override bool CheckAccess(EndpointIdentity identity, AuthorizationContext authContext)  
        {  
            Claim dnsClaim = authContext.Claims().Single(claim => claim.ClaimType == ClaimTypes.Dns);  
            return String.Equals(_expectedIdentity.IdentityClaim.Resource, dnsClaim.Resource);  
        }  

        public override bool TryGetIdentity(EndpointAddress reference, out EndpointIdentity identity)  
        {  
            identity = _expectedIdentity;  
            return true;  
        }  
    }  

    static class LinqExtensionForClaims  
    {  
        public static IEnumerable<Claim> Claims(this AuthorizationContext authContext)  
        {  
            if (null != authContext.ClaimSets)  
            {  
                foreach (ClaimSet claimSet in authContext.ClaimSets)  
                {  
                    if (null != claimSet)  
                    {  
                        foreach (Claim claim in claimSet)  
                        {  
                            yield return claim;  
                        }  
                    }  
                }  
            }  
        }  
    }  

    class Service : IService  
    {  
        public void DoSomething()  
        {  
            Console.WriteLine("Service called.");  
        }  
    }  

    class Program  
    {  
        static void Main(string[] args)  
        {  
            string hostname = Dns.GetHostEntry(String.Empty).HostName;  
            NetTcpBinding serviceBinding = new NetTcpBinding(SecurityMode.TransportWithMessageCredential);  

            ServiceHost serviceHost = new ServiceHost(typeof(Service), new Uri(String.Format("net.tcp://{0}:8080/Service", hostname)));  
            serviceHost.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, "8a 42 1b eb cf 8a 14 b1 de 83 d9 a5 70 88 0a 62 f9 bf 69 06");  
            ServiceEndpoint serviceEndpoint = serviceHost.AddServiceEndpoint(typeof(IService), serviceBinding, "Endpoint");  
            serviceHost.Open();  

            CustomBinding clientBinding = new CustomBinding(serviceBinding.CreateBindingElements());  
            SslStreamSecurityBindingElement sslStream = clientBinding.Elements.Find<SslStreamSecurityBindingElement>();  
            sslStream.IdentityVerifier = new DnsIdentityVerifier(serviceEndpoint.Address);  

            ChannelFactory<IService> channelFactory = new ChannelFactory<IService>(clientBinding, new EndpointAddress(serviceEndpoint.Address.Uri, UpnEndpointIdentity.CreateUpnIdentity("username@domain")));  
            channelFactory.Credentials.Windows.AllowNtlm = false;  
            IService channel = channelFactory.CreateChannel();  
            channel.DoSomething();  
        }  
    }  

建構函式

SslStreamSecurityBindingElement()

初始化 SslStreamSecurityBindingElement 類別的新執行個體。

SslStreamSecurityBindingElement(SslStreamSecurityBindingElement)

使用來自另一個 SslStreamSecurityBindingElement的值,初始化 SslStreamSecurityBindingElement 類別的新執行個體。

屬性

IdentityVerifier

取得或設定此繫結的身分識別驗證器。

RequireClientCertificate

取得或設定值,這個值會指定這個繫結是否需要用戶端憑證。

SslProtocols

指定使用用戶端認證類型 TcpClientCredentialType.Certificate 時所要交涉的 SSL/TLS 通訊協定清單。 此值可以是下列一或多個列舉成員的組合:Ssl3、Tls、Tls11、Tls12。

方法

BuildChannelFactory<TChannel>(BindingContext)

建立指定型別的通道處理站。

BuildChannelListener<TChannel>(BindingContext)

建立特定型別的通道接聽項。

BuildChannelListener<TChannel>(BindingContext)

初始化通道接聽項,以便從繫結內容接受指定之類型的通道。

(繼承來源 BindingElement)
BuildClientStreamUpgradeProvider(BindingContext)

根據提供的通道內容,於 StreamUpgradeProvider 的用戶端上建立執行個體。

BuildServerStreamUpgradeProvider(BindingContext)

根據提供的通道內容,於 StreamUpgradeProvider 的伺服器上建立執行個體。

BuildServerStreamUpgradeProvider(BindingContext)

根據提供的通道內容,於 StreamUpgradeProvider 的伺服器上建立執行個體。

(繼承來源 StreamUpgradeBindingElement)
CanBuildChannelFactory<TChannel>(BindingContext)

取得值,這個值會指出是否能建置指定型別的通道處理站。

CanBuildChannelListener<TChannel>(BindingContext)

取得值,這個值會指出是否能建置指定型別的通道接聽程式。

CanBuildChannelListener<TChannel>(BindingContext)

傳回值,指出繫結項目是否可以建置特定通道型別的通道接聽程式。

(繼承來源 BindingElement)
Clone()

建立新的執行個體,這個執行個體是目前執行個體的複本。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetProperty<T>(BindingContext)

BindingContext 中取得指定的物件。

GetTransportTokenAssertion()

取得 XmlElement,表示安全性繫結中所使用的傳輸權杖。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ShouldSerializeIdentityVerifier()

取得值,指出識別驗證器是否應該序列化。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

IPolicyExportExtension.ExportPolicy(MetadataExporter, PolicyConversionContext)

匯出關於繫結的自訂原則判斷提示。

適用於