Op Englesch liesen Editéieren

Deelen iwwer


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
Source:
AddressHeader.cs

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

C#
public static System.ServiceModel.Channels.AddressHeader CreateAddressHeader(object value);

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.

C#
// Obsolete
C#
// Obsolete

Applies to

.NET Framework 4.8.1 an aner Versiounen
Produkt Versiounen
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

CreateAddressHeader(Object, XmlObjectSerializer)

Source:
AddressHeader.cs
Source:
AddressHeader.cs

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

C#
public static System.ServiceModel.Channels.AddressHeader CreateAddressHeader(object value, System.Runtime.Serialization.XmlObjectSerializer serializer);

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.

C#
// Obsolete
C#
// Obsolete

Applies to

.NET Framework 4.8.1 an aner Versiounen
Produkt Versiounen
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

CreateAddressHeader(String, String, Object)

Source:
AddressHeader.cs
Source:
AddressHeader.cs

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

C#
public static System.ServiceModel.Channels.AddressHeader CreateAddressHeader(string name, string ns, object value);

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.

C#
// 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);
C#
// 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);

Applies to

.NET 10 (package-provided) an aner Versiounen
Produkt Versiounen
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
UWP 10.0

CreateAddressHeader(String, String, Object, XmlObjectSerializer)

Source:
AddressHeader.cs
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.

C#
public static System.ServiceModel.Channels.AddressHeader CreateAddressHeader(string name, string ns, object value, System.Runtime.Serialization.XmlObjectSerializer serializer);

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.

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

Applies to

.NET 10 (package-provided) an aner Versiounen
Produkt Versiounen
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
UWP 10.0