AddressHeader.CreateAddressHeader Method

Definition

Creates a new instance of the AddressHeader class.

Overloads

CreateAddressHeader(Object)

Creates a new instance of the AddressHeader class with a specified value.

CreateAddressHeader(Object, XmlObjectSerializer)

Creates a new instance of the AddressHeader class using a specified formatter to serialize the information item from a specified object.

CreateAddressHeader(String, String, Object)

Creates a new instance of the AddressHeader class with a specified value, name and namespace.

CreateAddressHeader(String, String, Object, XmlObjectSerializer)

Creates a new instance of the AddressHeader class with a specified name and namespace that uses a specified formatter to serialize the information item from a specified object.

Remarks

The object that contains the information item is serialized into the address header by an XmlObjectSerializer object.

CreateAddressHeader(Object)

Source:
AddressHeader.cs

Creates a new instance of the AddressHeader class with a specified value.

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

Parameters

value
Object

The information item for the address header.

Returns

The AddressHeader that contains the information item specified by the value parameter.

Examples

The following example shows how to create an address header using this method.

// Obsolete
// Obsolete
' Obsolete
' Obsolete

Applies to

CreateAddressHeader(Object, XmlObjectSerializer)

Source:
AddressHeader.cs

Creates a new instance of the AddressHeader class using a specified formatter to serialize the information item from a specified object.

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

Parameters

value
Object

The information item for the address header.

serializer
XmlObjectSerializer

The XmlObjectSerializer used to serialize the specified object in the value parameter.

Returns

The AddressHeader that contains the information item specified by the value parameter.

Exceptions

The formatter is null.

Examples

The following example shows how to create an address header using this method.

// Obsolete
// Obsolete
' Obsolete
' Obsolete

Applies to

CreateAddressHeader(String, String, Object)

Source:
AddressHeader.cs

Creates a new instance of the AddressHeader class with a specified value, name and namespace.

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

Parameters

name
String

The name of the address header.

ns
String

The namespace of the address header.

value
Object

The information item for the address header.

Returns

The AddressHeader with the specified name and ns that contains the information item specified by value.

Exceptions

The name is null or name.Length == 0.

Examples

The following example shows how to create an address header using this method.

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

Applies to

CreateAddressHeader(String, String, Object, XmlObjectSerializer)

Source:
AddressHeader.cs

Creates a new instance of the AddressHeader class with a specified name and namespace that uses a specified formatter to serialize the information item from a specified object.

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

Parameters

name
String

The name of the address header.

ns
String

The namespace of the address header.

value
Object

The information item for the address header.

serializer
XmlObjectSerializer

The XmlObjectSerializer used to serialize the specified object in the value parameter.

Returns

The AddressHeader with the specified name and ns that contains the information item specified by value.

Exceptions

name or serializer is null or name.Length == 0.

Examples

The following example shows how to create an address header using this method.

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

Applies to