WebChannelFactory<TChannel> Konstruktoren

Definition

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse.

Überlädt

WebChannelFactory<TChannel>()

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse.

WebChannelFactory<TChannel>(Binding)

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse.

WebChannelFactory<TChannel>(ServiceEndpoint)

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse.

WebChannelFactory<TChannel>(String)

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse.

WebChannelFactory<TChannel>(Type)

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse.

WebChannelFactory<TChannel>(Uri)

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse mit der angegebenen Uri.

WebChannelFactory<TChannel>(Binding, Uri)

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse mit der angegebenen Bindung und dem angegebenen Uri.

WebChannelFactory<TChannel>(String, Uri)

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse mit der angegebenen Endpunktkonfiguration und dem angegebenen Uri.

WebChannelFactory<TChannel>()

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse.

public:
 WebChannelFactory();
public WebChannelFactory ();
Public Sub New ()

Gilt für:

WebChannelFactory<TChannel>(Binding)

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse.

public:
 WebChannelFactory(System::ServiceModel::Channels::Binding ^ binding);
public WebChannelFactory (System.ServiceModel.Channels.Binding binding);
new System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)> : System.ServiceModel.Channels.Binding -> System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)>
Public Sub New (binding As Binding)

Parameter

binding
Binding

Die bei der Erstellung des Kanals zu verwendende Bindung.

Beispiele

Der folgende Code zeigt, wie Sie diesen Konstruktor verwenden, um einen WebChannelFactory<TChannel> zu erstellen und ihn zum Aufrufen eines WCF-Diensts zu verwenden.

Uri baseAddress = new Uri("http://localhost:8000");
WebServiceHost host = new WebServiceHost(typeof(Service), baseAddress);
try
{
    host.Open();
    WebHttpBinding binding = new WebHttpBinding();
    WebChannelFactory<IService> cf = new WebChannelFactory<IService>(binding);
    cf.Endpoint.Address = new EndpointAddress("http://localhost:8000");
    IService channel = cf.CreateChannel();
    string s;

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ");
    s = channel.EchoWithGet("Hello, world");
    Console.WriteLine("   Output: {0}", s);
}
catch (CommunicationException ex)
{
    Console.WriteLine("An exception occurred: " + ex.Message);
}
Dim baseAddress As New Uri("http://localhost:8000")
Dim host As New WebServiceHost(GetType(Service), baseAddress)
Try
    host.Open()
    Dim binding As New WebHttpBinding()
    Dim cf As New WebChannelFactory(Of IService)(binding)
    cf.Endpoint.Address = New EndpointAddress("http://localhost:8000")
    Dim channel As IService = cf.CreateChannel()
    Dim s As String

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ")
    s = channel.EchoWithGet("Hello, world")
    Console.WriteLine("   Output:  0}", s)
Catch ex As CommunicationException
    Console.WriteLine("An exception occurred: " + ex.Message)
End Try

Gilt für:

WebChannelFactory<TChannel>(ServiceEndpoint)

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse.

public:
 WebChannelFactory(System::ServiceModel::Description::ServiceEndpoint ^ endpoint);
public WebChannelFactory (System.ServiceModel.Description.ServiceEndpoint endpoint);
new System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)> : System.ServiceModel.Description.ServiceEndpoint -> System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)>
Public Sub New (endpoint As ServiceEndpoint)

Parameter

endpoint
ServiceEndpoint

Der bei der Erstellung des Kanals zu verwendende Endpunkt.

Beispiele

Der folgende Code zeigt, wie Sie diesen Konstruktor verwenden, um einen WebChannelFactory<TChannel> zu erstellen und ihn zum Aufrufen eines WCF-Diensts zu verwenden.

Uri baseAddress = new Uri("http://localhost:8000");
WebServiceHost host = new WebServiceHost(typeof(Service), baseAddress);
try
{
    host.Open();

    WebHttpBinding binding = new WebHttpBinding();
    ContractDescription desc = ContractDescription.GetContract(typeof(IService));
    EndpointAddress endpointAddress = new EndpointAddress("http://localhost:8000");
    ServiceEndpoint endpoint = new ServiceEndpoint(desc, binding, endpointAddress);

    WebChannelFactory<IService> cf = new WebChannelFactory<IService>(endpoint);
    IService channel = cf.CreateChannel();
    string s;

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ");
    s = channel.EchoWithGet("Hello, world");
    Console.WriteLine("   Output: {0}", s);
}
catch (CommunicationException ex)
{
    Console.WriteLine("An exception occurred: " + ex.Message);
}
Dim baseAddress As New Uri("http://localhost:8000")
Dim host As New WebServiceHost(GetType(Service), baseAddress)
Try
    host.Open()

    Dim binding As New WebHttpBinding()
    Dim desc As ContractDescription = ContractDescription.GetContract(GetType(IService))
    Dim endpointAddress As New EndpointAddress("http://localhost:8000")
    Dim endpoint As New ServiceEndpoint(desc, binding, endpointAddress)

    Dim cf As New WebChannelFactory(Of IService)(endpoint)
    Dim channel As IService = cf.CreateChannel()
    Dim s As String

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ")
    s = channel.EchoWithGet("Hello, world")
    Console.WriteLine("   Output:  0}", s)
Catch ex As CommunicationException
    Console.WriteLine("An exception occurred: " + ex.Message)
End Try

Gilt für:

WebChannelFactory<TChannel>(String)

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse.

public:
 WebChannelFactory(System::String ^ endpointConfigurationName);
public WebChannelFactory (string endpointConfigurationName);
new System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)> : string -> System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)>
Public Sub New (endpointConfigurationName As String)

Parameter

endpointConfigurationName
String

Der Name in der Anwendungskonfigurationsdatei, die zur Konfiguration des Kanals verwendet wird.

Beispiele

Im folgenden Code wird veranschaulicht, wie sie mithilfe dieses Konstruktors eine WebChannelFactory<TChannel> instance erstellen und zum Aufrufen eines WCF-Diensts verwenden.

Uri baseAddress = new Uri("http://localhost:8000");
WebServiceHost host = new WebServiceHost(typeof(Service), baseAddress);
try
{
    host.Open();

    // The endpoint name passed to the constructor must match an endpoint element
    // in the application configuration file
    WebChannelFactory<IService> cf = new WebChannelFactory<IService>("MyEndpoint");
    IService channel = cf.CreateChannel();
    string s;

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ");
    s = channel.EchoWithGet("Hello, world");
    Console.WriteLine("   Output: {0}", s);
}
catch (CommunicationException ex)
{
    Console.WriteLine("An exception occurred: " + ex.Message);
}
Dim baseAddress As New Uri("http://localhost:8000")
Dim host As New WebServiceHost(GetType(Service), baseAddress)
Try
    host.Open()

    ' The endpoint name passed to the constructor must match an endpoint element
    ' in the application configuration file
    Dim cf As New WebChannelFactory(Of IService)("MyEndpoint")
    Dim channel As IService = cf.CreateChannel()
    Dim s As String

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ")
    s = channel.EchoWithGet("Hello, world")
    Console.WriteLine("   Output:  0}", s)
Catch ex As CommunicationException
    Console.WriteLine("An exception occurred: " + ex.Message)
End Try

Hinweise

Der endpointConfigurationName-Parameter muss auf denselben Wert festgelegt werden wie das name-Attribut des <endpoint>-Elements in der Anwendungskonfigurationsdatei.

Gilt für:

WebChannelFactory<TChannel>(Type)

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse.

public:
 WebChannelFactory(Type ^ channelType);
public WebChannelFactory (Type channelType);
new System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)> : Type -> System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)>
Public Sub New (channelType As Type)

Parameter

channelType
Type

Der zu verwendende Kanaltyp.

Hinweise

Beim für den Typparameter übertragenen Typ muss es sich um eine Schnittstelle handeln.

Gilt für:

WebChannelFactory<TChannel>(Uri)

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse mit der angegebenen Uri.

public:
 WebChannelFactory(Uri ^ remoteAddress);
public WebChannelFactory (Uri remoteAddress);
new System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)> : Uri -> System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)>
Public Sub New (remoteAddress As Uri)

Parameter

remoteAddress
Uri

Der URI des aufgerufenen Webdiensts.

Beispiele

Im folgenden Code wird veranschaulicht, wie dieser Konstruktor zum Erstellen einer WebChannelFactory<TChannel>-Instanz und zum Aufrufen eines Dienstes verwendet wird.

Uri baseAddress = new Uri("http://localhost:8000");
WebServiceHost host = new WebServiceHost(typeof(Service), baseAddress);
try
{
    host.Open();

    WebChannelFactory<IService> cf = new WebChannelFactory<IService>(new Uri("http://localhost:8000"));
    IService channel = cf.CreateChannel();
    string s;

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ");
    s = channel.EchoWithGet("Hello, world");
    Console.WriteLine("   Output: {0}", s);
}
catch (CommunicationException ex)
{
    Console.WriteLine("An exception occurred: " + ex.Message);
}
Dim baseAddress As New Uri("http://localhost:8000")
Dim host As New WebServiceHost(GetType(Service), baseAddress)
Try
    host.Open()

    Dim cf As New WebChannelFactory(Of IService)(New Uri("http://localhost:8000"))
    Dim channel As IService = cf.CreateChannel()
    Dim s As String

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ")
    s = channel.EchoWithGet("Hello, world")
    Console.WriteLine("   Output:  0}", s)
Catch ex As CommunicationException
    Console.WriteLine("An exception occurred: " + ex.Message)
End Try

Gilt für:

WebChannelFactory<TChannel>(Binding, Uri)

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse mit der angegebenen Bindung und dem angegebenen Uri.

public:
 WebChannelFactory(System::ServiceModel::Channels::Binding ^ binding, Uri ^ remoteAddress);
public WebChannelFactory (System.ServiceModel.Channels.Binding binding, Uri remoteAddress);
new System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)> : System.ServiceModel.Channels.Binding * Uri -> System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)>
Public Sub New (binding As Binding, remoteAddress As Uri)

Parameter

binding
Binding

Die zu verwendende Bindung.

remoteAddress
Uri

Der URI des aufgerufenen Webdiensts.

Beispiele

Im folgenden Code wird veranschaulicht, wie dieser Konstruktor zum Erstellen einer WebChannelFactory<TChannel>-Instanz und zum Aufrufen eines Dienstes verwendet wird.

Uri baseAddress = new Uri("http://localhost:8000");
WebServiceHost host = new WebServiceHost(typeof(Service), baseAddress);
try
{
    host.Open();

    WebHttpBinding binding = new WebHttpBinding();
    WebChannelFactory<IService> cf = new WebChannelFactory<IService>(binding, new Uri("http://localhost:8000"));
    IService channel = cf.CreateChannel();
    string s;

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ");
    s = channel.EchoWithGet("Hello, world");
    Console.WriteLine("   Output: {0}", s);
}
catch (CommunicationException ex)
{
    Console.WriteLine("An exception occurred: " + ex.Message);
}
Dim baseAddress As New Uri("http://localhost:8000")
Dim host As New WebServiceHost(GetType(Service), baseAddress)
Try
    host.Open()

    Dim binding As New WebHttpBinding()
    Dim cf As New WebChannelFactory(Of IService)(binding, New Uri("http://localhost:8000"))
    Dim channel As IService = cf.CreateChannel()
    Dim s As String

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ")
    s = channel.EchoWithGet("Hello, world")
    Console.WriteLine("   Output:  0}", s)
Catch ex As CommunicationException
    Console.WriteLine("An exception occurred: " + ex.Message)
End Try

Gilt für:

WebChannelFactory<TChannel>(String, Uri)

Initialisiert eine neue Instanz der WebChannelFactory<TChannel>-Klasse mit der angegebenen Endpunktkonfiguration und dem angegebenen Uri.

public:
 WebChannelFactory(System::String ^ endpointConfigurationName, Uri ^ remoteAddress);
public WebChannelFactory (string endpointConfigurationName, Uri remoteAddress);
new System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)> : string * Uri -> System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)>
Public Sub New (endpointConfigurationName As String, remoteAddress As Uri)

Parameter

endpointConfigurationName
String

Der Name in der Anwendungskonfigurationsdatei, die zur Konfiguration des Kanals verwendet wird.

remoteAddress
Uri

Der URI des aufgerufenen Webdiensts.

Beispiele

Im folgenden Code wird veranschaulicht, wie dieser Konstruktor zum Erstellen einer WebChannelFactory<TChannel>-Instanz und zum Aufrufen eines Dienstes verwendet wird.

Uri baseAddress = new Uri("http://localhost:8000");
WebServiceHost host = new WebServiceHost(typeof(Service), baseAddress);
try
{
    host.Open();

    // The endpoint name passed to the constructor must match an endpoint element
    // in the application configuration file
    WebChannelFactory<IService> cf = new WebChannelFactory<IService>("MyEndpoint", new Uri("http://localhost:8000"));
    IService channel = cf.CreateChannel();
    string s;

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ");
    s = channel.EchoWithGet("Hello, world");
    Console.WriteLine("   Output: {0}", s);
}
catch (CommunicationException ex)
{
    Console.WriteLine("An exception occurred: " + ex.Message);
}
Dim baseAddress As New Uri("http://localhost:8000")
Dim host As New WebServiceHost(GetType(Service), baseAddress)
Try
    host.Open()

    ' The endpoint name passed to the constructor must match an endpoint element
    ' in the application configuration file
    Dim cf As New WebChannelFactory(Of IService)("MyEndpoint", New Uri("http://localhost:8000"))
    Dim channel As IService = cf.CreateChannel()
    Dim s As String

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ")
    s = channel.EchoWithGet("Hello, world")
    Console.WriteLine("   Output:  0}", s)
Catch ex As CommunicationException
    Console.WriteLine("An exception occurred: " + ex.Message)
End Try

Hinweise

Der endpointConfigurationName-Parameter muss auf denselben Wert festgelegt werden wie das name-Attribut des <endpoint>-Elements in der Anwendungskonfigurationsdatei.

Gilt für: