AddressHeader 类

定义

表示一个地址头,它包装的地址信息项用于标识终结点或与终结点进行交互。

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

示例

下面的示例演示如何创建地址头,如何访问其属性,如何将其添加到服务终结点,以及如何使用终结点承载服务。


// 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 由名称和命名空间表示,并具有一个值,该值包含用于标识终结点或与终结点进行交互的可选信息。 名称可通过 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 读取器。

GetHashCode()

为地址头提供一个唯一的哈希代码。

GetType()

获取当前实例的 Type

(继承自 Object)
GetValue<T>()

将来自当前地址头的信息项反序列化为具有指定类型的对象。

GetValue<T>(XmlObjectSerializer)

将来自当前地址头的信息项反序列化为具有指定类型的对象,该对象使用指定格式化程序对此信息进行序列化。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
OnWriteAddressHeaderContents(XmlDictionaryWriter)

当在派生类中重写时,在向流或文件写入地址头内容时调用。

OnWriteStartAddressHeader(XmlDictionaryWriter)

当在派生类中重写时,在开始向流或文件写入地址头内容时调用。

ToMessageHeader()

将地址头包装为消息头。

ToString()

返回表示当前对象的字符串。

(继承自 Object)
WriteAddressHeader(XmlDictionaryWriter)

使用指定 XmlDictionaryWriter 向流或文件写入地址头。

WriteAddressHeader(XmlWriter)

使用指定 XmlWriter 向流或文件写入地址头。

WriteAddressHeaderContents(XmlDictionaryWriter)

向流或文件写入地址头内容。

WriteStartAddressHeader(XmlDictionaryWriter)

开始向流或文件写入地址头内容。

适用于