共用方式為


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

使用指定的值來建立 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 參數指定之資訊項目的 value

範例

下列範例會示範如何使用這個方法來建立位址標頭。

// Obsolete
// Obsolete
' Obsolete
' Obsolete

適用於

CreateAddressHeader(Object, XmlObjectSerializer)

來源:
AddressHeader.cs
來源:
AddressHeader.cs
來源:
AddressHeader.cs

使用指定的格式器從指定的物件序列化此資訊項目,以建立 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

傳回

包含 value 參數指定之資訊項目的 AddressHeader

例外狀況

formatternull

範例

下列範例會示範如何使用這個方法來建立位址標頭。

// Obsolete
// Obsolete
' Obsolete
' Obsolete

適用於

CreateAddressHeader(String, String, Object)

來源:
AddressHeader.cs
來源:
AddressHeader.cs
來源:
AddressHeader.cs

使用指定的值、名稱和命名空間建立 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,它具有指定的 namens (其中包含 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.cs
來源:
AddressHeader.cs
來源:
AddressHeader.cs

使用指定的名稱和命名空間建立 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,它具有指定的 namens (其中包含 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)()

適用於