EndpointAddress 類別

定義

提供用戶端用來與服務端點通訊的唯一網路位址。

public ref class EndpointAddress
public class EndpointAddress
type EndpointAddress = class
Public Class EndpointAddress
繼承
EndpointAddress

範例

using System;
using System.Configuration;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;

using System.Text;

namespace Microsoft.WCF.Documentation
{
  class HostApplication
  {

    static void Main()
    {
      HostApplication app = new HostApplication();
      app.Run();
    }

    private void Run()
    {

            // Get base address from app settings in configuration
            Uri baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]);

            //Create new address headers for special services and add them to an array
            AddressHeader addressHeader1 = AddressHeader.CreateAddressHeader(
                "specialservice1", "http://localhost:8000/service", 1);
            AddressHeader addressHeader2 = AddressHeader.CreateAddressHeader(
                "specialservice2", "http://localhost:8000/service", 2);

            // Enumerate address headers and their properties from the array.
            AddressHeader[] addressHeaders = new AddressHeader[2] { addressHeader1, addressHeader2 };
            foreach (AddressHeader addressHeader in addressHeaders)
            {
                Console.WriteLine("AddressHeader - namespace:\t\t{0}", addressHeader.Namespace);
                Console.WriteLine("              - name:\t\t\t{0}", addressHeader.Name);
                Console.WriteLine("              - value:\t\t\t{0}", addressHeader.GetValue<int>());
                Console.WriteLine("              - type:\t\t\t{0}", addressHeader.GetType());
                Console.WriteLine("              - hashcode:\t\t{0}", addressHeader.GetHashCode());
                Console.WriteLine("              - equals addressHeader1:\t{0}", addressHeader.Equals(addressHeader1));
             //   Console.WriteLine("              - Is SOAP1.1 supported:\t{0}", addressHeader.ToMessageHeader().IsMessageVersionSupported(MessageVersion.WSAddressingSoap10));
                Console.WriteLine();
            }
            Console.WriteLine();

            //Add the array of address headers to an endpoint address
            EndpointAddress endpointAddress = new EndpointAddress(
                        new Uri("http://localhost:8003/servicemodelsamples/service"), addressHeaders);

            //Create a "special" service endpoint that uses the endpointAddress.
            string WSHttpBindingName = "Binding1";
            ServiceEndpoint specialServiceEndpoint = new ServiceEndpoint(
                ContractDescription.GetContract(typeof(CalculatorService)), new WSHttpBinding(WSHttpBindingName), endpointAddress
                );

            // Create a ServiceHost for the CalculatorService type that uses the base address.
            ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress);

            //Add the specialServiceEndpoint to the serviceHost.
            serviceHost.Description.Endpoints.Add(specialServiceEndpoint);

            // Enumerate the service endpoints and some of their properties from the serviceHost.
            Console.WriteLine("Service endpoints:");
            ServiceDescription desc = serviceHost.Description;
            foreach (ServiceEndpoint endpoint in desc.Endpoints)
            {
                Console.WriteLine("Endpoint - address:  {0}", endpoint.Address);
                Console.WriteLine("         - binding name:\t\t{0}", endpoint.Binding.Name);
                // Console.WriteLine("         - binding name:\t\t{0}", endpoint.);
                Console.WriteLine("         - contract name:\t\t{0}", endpoint.Contract.Name);
                Console.WriteLine("         - contains addressHeader1:\t{0}", endpoint.Address.Headers.Contains(addressHeader1));
                Console.WriteLine("         - count of address headers:\t{0}", endpoint.Address.Headers.Count);
                Console.WriteLine();
            }

            Console.WriteLine();

            // Open the ServiceHostBase to create listeners and start listening for messages.
            serviceHost.Open();

            // The service can now be accessed.
            Console.WriteLine("The service is ready.");
            Console.WriteLine("Press <ENTER> to terminate service.");
            Console.WriteLine();
            Console.ReadLine();

            // Close the ServiceHostBase to shutdown the service.
            serviceHost.Close();
        }
    }
  }

備註

端點位址可唯一識別服務的端點。

端點位址屬於服務端點,其中也包含端點的繫結、合約及行為。

EndpointAddress 包含 URI 和位址屬性,其中包括身分識別、WSDL 項目和選擇性標頭的集合。 選擇性標頭會用於提供額外的詳細位址資訊,以便識別端點或與端點互動。 例如,當有多個可用的執行個體時,它們可以用於指出要使用哪一個服務執行個體來處理來自特定使用者的傳入訊息。

您可以強制使用程式碼,或是透過組態以宣告的形式來指定服務的端點位址。 在程式碼中定義端點通常不太實用,因為部署之服務的繫結和位址通常與開發服務時所使用的繫結和位址不同。 使用組態定義服務端點會比較實用。

EndpointAddress 不會實作 ISerializable 介面,因此無法序列化。 如果是要公開成為服務合約一部分的端點,它必須是可序列化,而且必須符合 Web 服務定址 (WS-Addressing) 通訊協定。 EndpointAddress10EndpointAddressAugust2004 類別會分別提供符合 WS-Addressing 的 1.0 版本和 August 2004 版本標準的可序列化端點。

建構函式

EndpointAddress(String)

使用指定的 URI 字串,初始化 EndpointAddress 類別的新執行個體。

EndpointAddress(Uri, AddressHeader[])

使用指定的 URI 和標頭,初始化 EndpointAddress 類別的新執行個體。

EndpointAddress(Uri, EndpointIdentity, AddressHeader[])

使用指定的 URI、身分識別和標頭,初始化 EndpointAddress 類別的新執行個體。

EndpointAddress(Uri, EndpointIdentity, AddressHeaderCollection)

使用指定的 URI、身分識別和標頭集合,初始化 EndpointAddress 類別的新執行個體。

EndpointAddress(Uri, EndpointIdentity, AddressHeaderCollection, XmlDictionaryReader, XmlDictionaryReader)

使用指定的 URI、身分識別、標頭集合以及中繼資料和延伸讀取器,初始化 EndpointAddress 類別的新執行個體。

屬性

AnonymousUri

取得匿名 URI 的中性版本表示。

Headers

取得產生器 (Builder) 可建立之端點位址標頭的集合。

Identity

取得用於驗證之端點的身分識別。

IsAnonymous

取得值,這個值會指出端點是否為「匿名」。

IsNone

取得值,這個值會指出端點的 URI 是否為 NoneUri

NoneUri

取得不得對其傳送訊息之端點位址所使用的中性版本 URI。

Uri

取得端點的 URI。

方法

ApplyTo(Message)

將端點位址的 URI 和屬性指派給已指定訊息的標頭值。

Equals(Object)

傳回值,這個值會指出指定的物件是否相等於目前的端點位址。

GetHashCode()

提供目前端點位址的唯一雜湊程式碼。

GetReaderAtExtensions()

取得可提供存取延伸的 XML 字典讀取器。

GetReaderAtMetadata()

取得可提供存取端點之中繼資料的 XML 字典讀取器。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ReadFrom(AddressingVersion, XmlDictionaryReader)

從指定的 XML 字典讀取器讀取指定之位址版本的端點位址。

ReadFrom(AddressingVersion, XmlDictionaryReader, XmlDictionaryString, XmlDictionaryString)

從指定的 XML 字典讀取器讀取具有所指定限定名稱之指定位址版本的端點位址。

ReadFrom(AddressingVersion, XmlReader)

從指定的 XML 讀取器讀取指定之位址版本的端點位址。

ReadFrom(AddressingVersion, XmlReader, String, String)

從指定的 XML 讀取器讀取具有所指定限定名稱之指定位址版本的端點位址。

ReadFrom(XmlDictionaryReader)

從指定的 XML 字典讀取器讀取端點位址。

ReadFrom(XmlDictionaryReader, XmlDictionaryString, XmlDictionaryString)

從指定的 XML 字典讀取器讀取具有指定之限定名稱的端點位址。

ToString()

傳回包含在端點位址中之 URI 的標準字串表示。

WriteContentsTo(AddressingVersion, XmlDictionaryWriter)

將節點的所有子節點都儲存至指定的 XML 字典寫入器。

WriteContentsTo(AddressingVersion, XmlWriter)

將節點的所有子節點都儲存至指定的 XML 寫入器。

WriteTo(AddressingVersion, XmlDictionaryWriter)

將指定版本的目前端點位址儲存至指定的 XML 字典寫入器。

WriteTo(AddressingVersion, XmlDictionaryWriter, XmlDictionaryString, XmlDictionaryString)

將指定版本的目前端點位址儲存至具有指定之命名空間和本機名稱的 XML 字典寫入器。

WriteTo(AddressingVersion, XmlWriter)

將指定版本的目前端點位址儲存至指定的 XML 寫入器。

WriteTo(AddressingVersion, XmlWriter, String, String)

將指定版本的目前端點位址儲存至具有指定之命名空間和本機名稱的 XML 寫入器。

運算子

Equality(EndpointAddress, EndpointAddress)

傳回值,這個值會指出指定的端點位址是否不相等。

Inequality(EndpointAddress, EndpointAddress)

傳回值,這個值會指出指定的端點位址是否不相等。

適用於