共用方式為


AddressHeader 類別

定義

表示標頭,此標頭會封裝用來識別或是與端點互動的位址資訊項目。

public ref class AddressHeader abstract
public abstract class AddressHeader
type AddressHeader = class
Public MustInherit Class AddressHeader
繼承
AddressHeader

範例

下列範例將示範如何建立位址標頭、存取其屬性、將其新增至服務端點,以及使用此端點來裝載 (Host) 服務。


// Name property
AddressHeader addressHeaderWithName = AddressHeader.CreateAddressHeader("MyServiceName", "http://localhost:8000/service",1);
string addressHeaderName = addressHeaderWithName.Name;

//Put snippet here.
// Namespace property
AddressHeader addressHeaderWithNS = AddressHeader.CreateAddressHeader("MyServiceName", "http://localhost:8000/service",1);
string addressHeaderNS = addressHeaderWithNS.Namespace;

// Obsolete

// Obsolete

// Create 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);
AddressHeader[] addressHeaders = new AddressHeader[2] { addressHeader1, addressHeader2 };

// Endpoint address constructor with URI and address headers
EndpointAddress endpointAddressWithHeaders = new EndpointAddress(
    new Uri("http://localhost/silverlightsamples/service1"), addressHeaders
    );

// Confirm adddressHeader1 is in endpointAddressWithHeaders - boolHeaders returns True.
AddressHeaderCollection addressHeaderCollection = endpointAddressWithHeaders.Headers;
bool boolHeaders = addressHeaderCollection.Contains(addressHeader1);

//Create address headers with XmlObjectSerializer specified
XmlObjectSerializer serializer = new DataContractSerializer(typeof(int));
AddressHeader addressHeaderWithObjSer = AddressHeader.CreateAddressHeader("MyServiceName", "http://localhost:8000/service", 1, serializer);
int value = addressHeaderWithObjSer.GetValue<int>();

// Name property
AddressHeader addressHeaderWithName = AddressHeader.CreateAddressHeader("MyServiceName", "http://localhost:8000/service",1);
string addressHeaderName = addressHeaderWithName.Name;

//Put snippet here.
// Namespace property
AddressHeader addressHeaderWithNS = AddressHeader.CreateAddressHeader("MyServiceName", "http://localhost:8000/service",1);
string addressHeaderNS = addressHeaderWithNS.Namespace;

// Obsolete

// Obsolete

// Create 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);
AddressHeader[] addressHeaders = new AddressHeader[2] { addressHeader1, addressHeader2 };

// Endpoint address constructor with URI and address headers
EndpointAddress endpointAddressWithHeaders = new EndpointAddress(
    new Uri("http://localhost/silverlightsamples/service1"), addressHeaders
    );

// Confirm adddressHeader1 is in endpointAddressWithHeaders - boolHeaders returns True.
AddressHeaderCollection addressHeaderCollection = endpointAddressWithHeaders.Headers;
bool boolHeaders = addressHeaderCollection.Contains(addressHeader1);

//Create address headers with XmlObjectSerializer specified
XmlObjectSerializer serializer = new DataContractSerializer(typeof(int));
AddressHeader addressHeaderWithObjSer = AddressHeader.CreateAddressHeader("MyServiceName", "http://localhost:8000/service", 1, serializer);
int value = addressHeaderWithObjSer.GetValue<int>();

' Name property
Dim addressHeaderWithName As AddressHeader = AddressHeader.CreateAddressHeader("MyServiceName", "http://localhost:8000/service",1)
Dim addressHeaderName As String = addressHeaderWithName.Name

'Put snippet here.
' Namespace property
Dim addressHeaderWithNS As AddressHeader = AddressHeader.CreateAddressHeader("MyServiceName", "http://localhost:8000/service",1)
Dim addressHeaderNS As String = addressHeaderWithNS.Namespace

' Obsolete

' Obsolete

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

' Endpoint address constructor with URI and address headers
Dim endpointAddressWithHeaders As New EndpointAddress(New Uri("http://localhost/silverlightsamples/service1"), addressHeaders)

' Confirm adddressHeader1 is in endpointAddressWithHeaders - boolHeaders returns True.
Dim addressHeaderCollection As AddressHeaderCollection = endpointAddressWithHeaders.Headers
Dim boolHeaders As Boolean = addressHeaderCollection.Contains(addressHeader1)

'Create address headers with XmlObjectSerializer specified
Dim serializer As XmlObjectSerializer = New DataContractSerializer(GetType(Integer))
Dim addressHeaderWithObjSer As AddressHeader = AddressHeader.CreateAddressHeader("MyServiceName", "http://localhost:8000/service", 1, serializer)
Dim value As Integer = addressHeaderWithObjSer.GetValue(Of Integer)()

' Name property
Dim addressHeaderWithName As AddressHeader = AddressHeader.CreateAddressHeader("MyServiceName", "http://localhost:8000/service",1)
Dim addressHeaderName As String = addressHeaderWithName.Name

'Put snippet here.
' Namespace property
Dim addressHeaderWithNS As AddressHeader = AddressHeader.CreateAddressHeader("MyServiceName", "http://localhost:8000/service",1)
Dim addressHeaderNS As String = addressHeaderWithNS.Namespace

' Obsolete

' Obsolete

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

' Endpoint address constructor with URI and address headers
Dim endpointAddressWithHeaders As New EndpointAddress(New Uri("http://localhost/silverlightsamples/service1"), addressHeaders)

' Confirm adddressHeader1 is in endpointAddressWithHeaders - boolHeaders returns True.
Dim addressHeaderCollection As AddressHeaderCollection = endpointAddressWithHeaders.Headers
Dim boolHeaders As Boolean = addressHeaderCollection.Contains(addressHeader1)

'Create address headers with XmlObjectSerializer specified
Dim serializer As XmlObjectSerializer = New DataContractSerializer(GetType(Integer))
Dim addressHeaderWithObjSer As AddressHeader = AddressHeader.CreateAddressHeader("MyServiceName", "http://localhost:8000/service", 1, serializer)
Dim value As Integer = addressHeaderWithObjSer.GetValue(Of Integer)()

備註

AddressHeader 會根據名稱和命名空間 (Namespace) 來表示特性,而且它有一個值包含了用來識別或是與端點互動的選擇性資訊。 此名稱可由 Name 屬性來存取,而命名空間則可由 Namespace 屬性來存取。

建構函式

AddressHeader()

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

屬性

Name

當實作時,會取得位址標頭的名稱。

Namespace

當實作時,會取得位址標頭的命名空間。

方法

CreateAddressHeader(Object)

使用指定的值來建立 AddressHeader 類別的新執行個體。

CreateAddressHeader(Object, XmlObjectSerializer)

使用指定的格式器從指定的物件序列化此資訊項目,以建立 AddressHeader 類別的新執行個體。

CreateAddressHeader(String, String, Object)

使用指定的值、名稱和命名空間建立 AddressHeader 類別的新執行個體。

CreateAddressHeader(String, String, Object, XmlObjectSerializer)

使用指定的名稱和命名空間建立 AddressHeader 類別的新執行個體 (此類別會使用指定的格式器從指定的物件序列化此資訊項目)。

Equals(Object)

判斷指定之物件中的資訊項目是否等於包含在目前位址標頭中的物件。

GetAddressHeaderReader()

傳回可以序列化目前位址標頭物件的 XML 讀取器 (Reader)。

GetHashCode()

為位址標頭提供唯一的雜湊程式碼。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetValue<T>()

將目前位址標頭中的資訊項目還原序列化成指定之型別的物件。

GetValue<T>(XmlObjectSerializer)

將目前位址標頭中的資訊項目還原序列化成指定之型別的物件 (此型別會使用指定的格式器來序列化這項資訊)。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
OnWriteAddressHeaderContents(XmlDictionaryWriter)

在衍生類別 (Derived Class) 中覆寫時,會在位址標頭內容寫入資料流或檔案時叫用 (Invoke)。

OnWriteStartAddressHeader(XmlDictionaryWriter)

在衍生類別中覆寫時,會在位址標頭內容開始寫入資料流或檔案時叫用。

ToMessageHeader()

將此位址標頭包裝成訊息標頭。

ToString()

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

(繼承來源 Object)
WriteAddressHeader(XmlDictionaryWriter)

使用指定的 XmlDictionaryWriter 將位址標頭寫入資料流或檔案中。

WriteAddressHeader(XmlWriter)

使用指定的 XmlWriter 將位址標頭寫入資料流或檔案中。

WriteAddressHeaderContents(XmlDictionaryWriter)

將位址標頭內容寫入資料流或檔案中。

WriteStartAddressHeader(XmlDictionaryWriter)

開始將位址標頭內容寫入資料流或檔案中。

適用於