WebChannelFactory<TChannel> Конструкторы

Определение

Инициализирует новый экземпляр класса WebChannelFactory<TChannel>.Initializes a new instance of the WebChannelFactory<TChannel> class.

Перегрузки

WebChannelFactory<TChannel>()

Инициализирует новый экземпляр класса WebChannelFactory<TChannel>.Initializes a new instance of the WebChannelFactory<TChannel> class.

WebChannelFactory<TChannel>(Binding)

Инициализирует новый экземпляр класса WebChannelFactory<TChannel>.Initializes a new instance of the WebChannelFactory<TChannel> class.

WebChannelFactory<TChannel>(ServiceEndpoint)

Инициализирует новый экземпляр класса WebChannelFactory<TChannel>.Initializes a new instance of the WebChannelFactory<TChannel> class.

WebChannelFactory<TChannel>(Uri)

Инициализирует новый экземпляр класса WebChannelFactory<TChannel> указанным значением Uri.Initializes a new instance of the WebChannelFactory<TChannel> class with the specified Uri.

WebChannelFactory<TChannel>(Binding, Uri)

Инициализирует новый экземпляр класса WebChannelFactory<TChannel> с заданной привязкой и свойством Uri.Initializes a new instance of the WebChannelFactory<TChannel> class with the specified binding and Uri.

WebChannelFactory<TChannel>(String)

Инициализирует новый экземпляр класса WebChannelFactory<TChannel>.Initializes a new instance of the WebChannelFactory<TChannel> class.

WebChannelFactory<TChannel>(String, Uri)

Инициализирует новый экземпляр класса WebChannelFactory<TChannel> с заданной конфигурацией конечной точки и свойством Uri.Initializes a new instance of the WebChannelFactory<TChannel> class with the specified endpoint configuration and Uri.

WebChannelFactory<TChannel>(Type)

Инициализирует новый экземпляр класса WebChannelFactory<TChannel>.Initializes a new instance of the WebChannelFactory<TChannel> class.

WebChannelFactory<TChannel>()

Инициализирует новый экземпляр класса WebChannelFactory<TChannel>.Initializes a new instance of the WebChannelFactory<TChannel> class.

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

WebChannelFactory<TChannel>(Binding)

Инициализирует новый экземпляр класса WebChannelFactory<TChannel>.Initializes a new instance of the WebChannelFactory<TChannel> class.

public:
 WebChannelFactory(System::ServiceModel::Channels::Binding ^ binding);
public WebChannelFactory (System.ServiceModel.Channels.Binding binding);
new System.ServiceModel.Web.WebChannelFactory<'Channel> : System.ServiceModel.Channels.Binding -> System.ServiceModel.Web.WebChannelFactory<'Channel>

Параметры

binding
Binding

Привязка, используемая при создании канала.The binding to use when creating the channel.

Примеры

В следующем коде показано, как использовать этот конструктор для создания WebChannelFactory<TChannel> и его использования для вызова службы WCF.The following code shows how use this constructor to create a WebChannelFactory<TChannel> and use it to call a WCF service.

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

WebChannelFactory<TChannel>(ServiceEndpoint)

Инициализирует новый экземпляр класса WebChannelFactory<TChannel>.Initializes a new instance of the WebChannelFactory<TChannel> class.

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

Параметры

endpoint
ServiceEndpoint

Конечная точка, используемая при создании канала.The endpoint to use when creating the channel.

Примеры

В следующем коде показано, как использовать этот конструктор для создания WebChannelFactory<TChannel> и его использования для вызова службы WCF.The following code shows how use this constructor to create a WebChannelFactory<TChannel> and use it to call a WCF service.

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

WebChannelFactory<TChannel>(Uri)

Инициализирует новый экземпляр класса WebChannelFactory<TChannel> указанным значением Uri.Initializes a new instance of the WebChannelFactory<TChannel> class with the specified Uri.

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

Параметры

remoteAddress
Uri

URL вызываемой веб-службы.The URI of the Web service that is called.

Примеры

В следующем примере кода показано, как использовать данный конструктор для создания экземпляра WebChannelFactory<TChannel> и использовать его для вызова службы.The following code shows how to use this constructor to create a WebChannelFactory<TChannel> instance and call a service.

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

WebChannelFactory<TChannel>(Binding, Uri)

Инициализирует новый экземпляр класса WebChannelFactory<TChannel> с заданной привязкой и свойством Uri.Initializes a new instance of the WebChannelFactory<TChannel> class with the specified binding and 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> : System.ServiceModel.Channels.Binding * Uri -> System.ServiceModel.Web.WebChannelFactory<'Channel>

Параметры

binding
Binding

Используемая привязка.The binding to use.

remoteAddress
Uri

URL вызываемой веб-службы.The URI of the Web service that is called.

Примеры

В следующем примере кода показано, как использовать данный конструктор для создания экземпляра WebChannelFactory<TChannel> и использовать его для вызова службы.The following code shows how to use this constructor to create a WebChannelFactory<TChannel> instance and call a service.

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

WebChannelFactory<TChannel>(String)

Инициализирует новый экземпляр класса WebChannelFactory<TChannel>.Initializes a new instance of the WebChannelFactory<TChannel> class.

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

Параметры

endpointConfigurationName
String

Имя в файле конфигурации приложения, в котором содержатся параметры настройки канала.The name within the application configuration file where the channel is configured.

Примеры

В следующем коде показано, как использовать этот конструктор для создания WebChannelFactory<TChannel> экземпляра и его использования для вызова службы WCF.The following code shows how use this constructor to create a WebChannelFactory<TChannel> instance and use it to call a WCF service.

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

Комментарии

Параметр endpointConfigurationName должен быть задан с тем же значением, что и атрибут name элемента <endpoint> в файле конфигурации приложения.The endpointConfigurationName parameter must be set to the same value as the name attribute of the <endpoint> element in the application configuration file.

WebChannelFactory<TChannel>(String, Uri)

Инициализирует новый экземпляр класса WebChannelFactory<TChannel> с заданной конфигурацией конечной точки и свойством Uri.Initializes a new instance of the WebChannelFactory<TChannel> class with the specified endpoint configuration and Uri.

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

Параметры

endpointConfigurationName
String

Имя в файле конфигурации приложения, в котором содержатся параметры настройки канала.The name within the application configuration file where the channel is configured.

remoteAddress
Uri

URL вызываемой веб-службы.The URI of the Web service that is called.

Примеры

В следующем примере кода показано, как использовать данный конструктор для создания экземпляра WebChannelFactory<TChannel> и использовать его для вызова службы.The following code shows how to use this constructor to create a WebChannelFactory<TChannel> instance and call a service.

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

Комментарии

Параметр endpointConfigurationName должен быть задан с тем же значением, что и атрибут name элемента <endpoint> в файле конфигурации приложения.The endpointConfigurationName parameter must be set to the same value as the name attribute of the <endpoint> element in the application configuration file.

WebChannelFactory<TChannel>(Type)

Инициализирует новый экземпляр класса WebChannelFactory<TChannel>.Initializes a new instance of the WebChannelFactory<TChannel> class.

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

Параметры

channelType
Type

Тип используемого канала.The channel type to use.

Комментарии

Тип, передаваемый для параметра типа, должен быть интерфейсом.The type passed for the type parameter must be an interface.

Применяется к