语言

ChannelFactory<TChannel>.CreateChannel 方法

定义

创建指定类型的通道到指定的终结点地址。

重载

名称 说明
CreateChannel(Binding, EndpointAddress, Uri)

创建指定类型的通道,该通道用于在配置有指定绑定的指定传输地址处将消息发送到服务终结点。

CreateChannel(EndpointAddress, Uri)

创建一个通道,该通道用于通过指定的传输地址将消息发送到特定终结点地址中的服务。

CreateChannel(Binding, EndpointAddress)

创建一个指定类型的通道,该通道用于将消息发送到配置有指定绑定的服务终结点。

CreateChannel(EndpointAddress)

创建一个通道,用于在特定终结点地址将消息发送到服务。

CreateChannel()

创建指定类型的通道到指定的终结点地址。

CreateChannel(String)

创建一个通道,用于将消息发送到其终结点以指定方式配置的服务。

注解

为类创建类型 TChannel为泛型参数的通道。

CreateChannel(Binding, EndpointAddress, Uri)

Source:
ChannelFactory.cs
Source:
ChannelFactory.cs
Source:
ChannelFactory.cs

创建指定类型的通道,该通道用于在配置有指定绑定的指定传输地址处将消息发送到服务终结点。

public:
 static TChannel CreateChannel(System::ServiceModel::Channels::Binding ^ binding, System::ServiceModel::EndpointAddress ^ endpointAddress, Uri ^ via);
public static TChannel CreateChannel(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress endpointAddress, Uri via);
static member CreateChannel : System.ServiceModel.Channels.Binding * System.ServiceModel.EndpointAddress * Uri -> 'Channel
Public Shared Function CreateChannel (binding As Binding, endpointAddress As EndpointAddress, via As Uri) As TChannel

参数

binding
Binding

Binding用于配置终结点的终结点。

endpointAddress
EndpointAddress

提供 EndpointAddress 服务的位置。

via
Uri

Uri包含通道向其发送消息的传输地址。

返回

TChannel

TChannel工厂创建的类型IChannel。

例外

具有不支持的 ChannelFactory 双工操作。

示例


 EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");
 Uri uri = new Uri("http://localhost:8000/Via");

 IRequestChannel channel =
ChannelFactory<IRequestChannel>.CreateChannel(binding, address, uri);
 channel.Open();
class Program : ChannelFactory<IService1Channel>
{
    static void Main(string[] args)
    {
        IService1Channel channel = CreateChannel("BasicHttpBinding_IService1");
        channel.Open();

        channel.Close();
    }
}

适用于

CreateChannel(EndpointAddress, Uri)

Source:
ChannelFactory.cs
Source:
ChannelFactory.cs
Source:
ChannelFactory.cs

创建一个通道,该通道用于通过指定的传输地址将消息发送到特定终结点地址中的服务。

public:
 virtual TChannel CreateChannel(System::ServiceModel::EndpointAddress ^ address, Uri ^ via);
public virtual TChannel CreateChannel(System.ServiceModel.EndpointAddress address, Uri via);
abstract member CreateChannel : System.ServiceModel.EndpointAddress * Uri -> 'Channel
override this.CreateChannel : System.ServiceModel.EndpointAddress * Uri -> 'Channel
Public Overridable Function CreateChannel (address As EndpointAddress, via As Uri) As TChannel

参数

address
EndpointAddress

提供 EndpointAddress 服务的位置。

via
Uri

Uri包含通道向其发送消息的传输地址。

返回

TChannel

TChannel工厂创建的类型IChannel。

实现

例外

address 是 null。

具有不支持的 ChannelFactory 双工操作。

示例

    BasicHttpBinding binding = new BasicHttpBinding();
    EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");
Uri via = new Uri("http://localhost:8000/Via");

ChannelFactory<IRequestChannel> factory = new ChannelFactory<IRequestChannel>(binding);

    IRequestChannel channel = factory.CreateChannel(address, via);
    channel.Open();
    Message request = Message.CreateMessage(MessageVersion.Soap11, "hello");
    Message reply = channel.Request(request);
    Console.Out.WriteLine(reply.Headers.Action);
    reply.Close();
    channel.Close();
    factory.Close();

适用于

CreateChannel(Binding, EndpointAddress)

Source:
ChannelFactory.cs
Source:
ChannelFactory.cs
Source:
ChannelFactory.cs

创建一个指定类型的通道,该通道用于将消息发送到配置有指定绑定的服务终结点。

public:
 static TChannel CreateChannel(System::ServiceModel::Channels::Binding ^ binding, System::ServiceModel::EndpointAddress ^ endpointAddress);
public static TChannel CreateChannel(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress endpointAddress);
static member CreateChannel : System.ServiceModel.Channels.Binding * System.ServiceModel.EndpointAddress -> 'Channel
Public Shared Function CreateChannel (binding As Binding, endpointAddress As EndpointAddress) As TChannel

参数

binding
Binding

Binding用于配置终结点的终结点。

endpointAddress
EndpointAddress

提供 EndpointAddress 服务的位置。

返回

TChannel

TChannel工厂创建的类型IChannel。

例外

具有不支持的 ChannelFactory 双工操作。

示例


       EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");
       IRequestChannel channel = ChannelFactory<IRequestChannel>.CreateChannel(binding, address);
       channel.Open();

适用于

CreateChannel(EndpointAddress)

Source:
ChannelFactory.cs
Source:
ChannelFactory.cs
Source:
ChannelFactory.cs

创建一个通道,用于在特定终结点地址将消息发送到服务。

public:
 virtual TChannel CreateChannel(System::ServiceModel::EndpointAddress ^ address);
public TChannel CreateChannel(System.ServiceModel.EndpointAddress address);
abstract member CreateChannel : System.ServiceModel.EndpointAddress -> 'Channel
override this.CreateChannel : System.ServiceModel.EndpointAddress -> 'Channel
Public Function CreateChannel (address As EndpointAddress) As TChannel

参数

address
EndpointAddress

提供 EndpointAddress 服务的位置。

返回

TChannel

TChannel工厂创建的类型IChannel。

实现

例外

address 是 null。

示例

BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");
ChannelFactory<IRequestChannel> factory = new ChannelFactory<IRequestChannel>(binding);
factory.CreateChannel(address);

适用于

CreateChannel()

Source:
ChannelFactory.cs
Source:
ChannelFactory.cs
Source:
ChannelFactory.cs

创建指定类型的通道到指定的终结点地址。

public:
 TChannel CreateChannel();
public TChannel CreateChannel();
member this.CreateChannel : unit -> 'Channel
Public Function CreateChannel () As TChannel

返回

TChannel

TChannel工厂创建的类型IChannel。

示例

IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>(bindingParams);
factory.Open();
EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");
IRequestChannel channel = factory.CreateChannel(address);
channel.Open();

注解

为类创建类型 TChannel为泛型参数的通道。

适用于

CreateChannel(String)

创建一个通道,用于将消息发送到其终结点以指定方式配置的服务。

protected:
 static TChannel CreateChannel(System::String ^ endpointConfigurationName);
protected static TChannel CreateChannel(string endpointConfigurationName);
static member CreateChannel : string -> 'Channel
Protected Shared Function CreateChannel (endpointConfigurationName As String) As TChannel

参数

endpointConfigurationName
String

用于服务的终结点配置的名称。

返回

TChannel

TChannel工厂创建的类型IChannel。

例外

具有不支持的 ChannelFactory 双工操作。

示例

    BasicHttpBinding binding = new BasicHttpBinding();
    EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");

    ChannelFactory<IRequestChannel> factory =
        new ChannelFactory<IRequestChannel>(binding, address);

    IRequestChannel channel = factory.CreateChannel();
    channel.Open();
    Message request = Message.CreateMessage(MessageVersion.Soap11, "hello");
    Message reply = channel.Request(request);
    Console.Out.WriteLine(reply.Headers.Action);
    reply.Close();
    channel.Close();
    factory.Close();
}

适用于