ServiceEndpoint.Name 屬性

定義

取得或設定服務端點的名稱。

C#
public string Name { get; set; }

屬性值

服務端點的名稱。 預設值是繫結名稱和合約描述名稱的串連。 例如,Name +'_' + Name

範例

C#
Uri baseAddress = new Uri("http://localhost:8001/Simple");
ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress);

ServiceEndpoint endpoint = serviceHost.AddServiceEndpoint(
    typeof(ICalculator),
    new WSHttpBinding(),
    "CalculatorServiceObject");

Console.WriteLine("Service endpoint {0} contains the following:", endpoint.Name);
Console.WriteLine("Binding: {0}", endpoint.Binding.ToString());
Console.WriteLine("Contract: {0}", endpoint.Contract.ToString());
Console.WriteLine("ListenUri: {0}", endpoint.ListenUri.ToString());
Console.WriteLine("ListenUriMode: {0}", endpoint.ListenUriMode.ToString());

備註

服務可能會有多個端點,因此端點 Name 會與服務的名稱有所區別。 服務名稱是使用 Name 屬性來存取。

備註

從服務存取時,這個屬性會由 < 端點 name=「 endpointName 」 > 組態專案填入。 在用戶端存取時,這個屬性為 null。 呼叫屬性 getter 時 (同樣是在用戶端),會根據合約和繫結在這個屬性中填入預設值。

適用於

產品 版本
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
UWP 10.0