共用方式為


EndpointIdentity.CreateSpnIdentity(String) 方法

定義

使用指定的名稱建立伺服器主要名稱 (SPN) 身分識別。

public:
 static System::ServiceModel::EndpointIdentity ^ CreateSpnIdentity(System::String ^ spnName);
public static System.ServiceModel.EndpointIdentity CreateSpnIdentity (string spnName);
static member CreateSpnIdentity : string -> System.ServiceModel.EndpointIdentity
Public Shared Function CreateSpnIdentity (spnName As String) As EndpointIdentity

參數

spnName
String

SPN 身分識別的名稱。

傳回

EndpointIdentity

與指定之 EndpointIdentity 關聯的 SPN spnName

例外狀況

spnNamenull

範例

下列程式碼將示範如何呼叫這個方法。

// Create the service host.
ServiceHost myServiceHost = new ServiceHost(typeof(Calculator));

// Create the binding.
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType =
     MessageCredentialType.Windows;

// Disable credential negotiation and establishment of the
// security context.
binding.Security.Message.NegotiateServiceCredential = false;
binding.Security.Message.EstablishSecurityContext = false;

// Create a URI for the endpoint address.
Uri httpUri = new Uri("http://localhost/Calculator");

// Create the EndpointAddress with the SPN for the Identity.
EndpointAddress ea = new EndpointAddress(httpUri,
    EndpointIdentity.CreateSpnIdentity("service_spn_name"));

// Get the contract from the ICalculator interface (not shown here).
// See the sample applications for an example of the ICalculator.
ContractDescription contract = ContractDescription.GetContract(
    typeof(ICalculator));

// Create a new ServiceEndpoint.
ServiceEndpoint se = new ServiceEndpoint(contract, binding, ea);

// Add the service endpoint to the service.
myServiceHost.Description.Endpoints.Add(se);

// Open the service.
myServiceHost.Open();
Console.WriteLine("Listening...");
Console.ReadLine();

// Close the service.
myServiceHost.Close();

備註

使用此身分識別連線到端點的安全 WCF 用戶端會在使用端點執行 SSPI 驗證時使用 SPN。

這個靜態方法會使用 SpnEndpointIdentity 做為輸入參數來呼叫其建構函式 SpnEndpointIdentity,藉此建立 spnName 的執行個體。

如果是以空字串指定 spnName,則驗證程序會盡可能從 Kerberos 退回使用 NTLM。 如果 AllowNtlmfalse,驗證就會失敗。

適用於