AddressHeader.CreateAddressHeader 方法

定义

创建 AddressHeader 类的新实例。

重载

CreateAddressHeader(Object)

使用指定的值创建 AddressHeader 类的新实例。

CreateAddressHeader(Object, XmlObjectSerializer)

创建 AddressHeader 类的新实例,使用指定的格式化程序对指定对象的信息项进行序列化。

CreateAddressHeader(String, String, Object)

用指定的值、名称和命名空间创建 AddressHeader 类的新实例。

CreateAddressHeader(String, String, Object, XmlObjectSerializer)

使用指定名称和命名空间创建 AddressHeader 类的新实例,该实例使用指定的格式化程序对指定对象的信息项进行序列化。

注解

通过一个 XmlObjectSerializer 对象将包含信息项的对象序列化到地址头中。

CreateAddressHeader(Object)

使用指定的值创建 AddressHeader 类的新实例。

public:
 static System::ServiceModel::Channels::AddressHeader ^ CreateAddressHeader(System::Object ^ value);
public static System.ServiceModel.Channels.AddressHeader CreateAddressHeader (object value);
static member CreateAddressHeader : obj -> System.ServiceModel.Channels.AddressHeader
Public Shared Function CreateAddressHeader (value As Object) As AddressHeader

参数

value
Object

为地址头提供的信息项。

返回

AddressHeader

包含 AddressHeader 参数指定的信息项的 value

示例

下面的示例演示如何使用此方法创建地址头。

// Obsolete
// Obsolete
' Obsolete
' Obsolete

适用于

CreateAddressHeader(Object, XmlObjectSerializer)

创建 AddressHeader 类的新实例,使用指定的格式化程序对指定对象的信息项进行序列化。

public:
 static System::ServiceModel::Channels::AddressHeader ^ CreateAddressHeader(System::Object ^ value, System::Runtime::Serialization::XmlObjectSerializer ^ serializer);
public static System.ServiceModel.Channels.AddressHeader CreateAddressHeader (object value, System.Runtime.Serialization.XmlObjectSerializer serializer);
static member CreateAddressHeader : obj * System.Runtime.Serialization.XmlObjectSerializer -> System.ServiceModel.Channels.AddressHeader
Public Shared Function CreateAddressHeader (value As Object, serializer As XmlObjectSerializer) As AddressHeader

参数

value
Object

为地址头提供的信息项。

serializer
XmlObjectSerializer

用于序列化 XmlObjectSerializer 参数中的指定对象的 value

返回

AddressHeader

包含 value 参数指定的信息项的 AddressHeader

例外

formatternull

示例

下面的示例演示如何使用此方法创建地址头。

// Obsolete
// Obsolete
' Obsolete
' Obsolete

适用于

CreateAddressHeader(String, String, Object)

用指定的值、名称和命名空间创建 AddressHeader 类的新实例。

public:
 static System::ServiceModel::Channels::AddressHeader ^ CreateAddressHeader(System::String ^ name, System::String ^ ns, System::Object ^ value);
public static System.ServiceModel.Channels.AddressHeader CreateAddressHeader (string name, string ns, object value);
static member CreateAddressHeader : string * string * obj -> System.ServiceModel.Channels.AddressHeader
Public Shared Function CreateAddressHeader (name As String, ns As String, value As Object) As AddressHeader

参数

name
String

地址头的名称。

ns
String

地址头的命名空间。

value
Object

为地址头提供的信息项。

返回

AddressHeader

具有指定 AddressHeadername 并且包含 ns 指定的信息项的 value

例外

namenullname.Length == 0。

示例

下面的示例演示如何使用此方法创建地址头。

// 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 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 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 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)

适用于

CreateAddressHeader(String, String, Object, XmlObjectSerializer)

使用指定名称和命名空间创建 AddressHeader 类的新实例,该实例使用指定的格式化程序对指定对象的信息项进行序列化。

public:
 static System::ServiceModel::Channels::AddressHeader ^ CreateAddressHeader(System::String ^ name, System::String ^ ns, System::Object ^ value, System::Runtime::Serialization::XmlObjectSerializer ^ serializer);
public static System.ServiceModel.Channels.AddressHeader CreateAddressHeader (string name, string ns, object value, System.Runtime.Serialization.XmlObjectSerializer serializer);
static member CreateAddressHeader : string * string * obj * System.Runtime.Serialization.XmlObjectSerializer -> System.ServiceModel.Channels.AddressHeader
Public Shared Function CreateAddressHeader (name As String, ns As String, value As Object, serializer As XmlObjectSerializer) As AddressHeader

参数

name
String

地址头的名称。

ns
String

地址头的命名空间。

value
Object

为地址头提供的信息项。

serializer
XmlObjectSerializer

用于序列化 XmlObjectSerializer 参数中的指定对象的 value

返回

AddressHeader

具有指定 AddressHeadername 并且包含 ns 指定的信息项的 value

例外

nameserializernull,或 name.Length == 0。

示例

下面的示例演示如何使用此方法创建地址头。

//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>();
//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>();
'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)()
'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)()

适用于