ChannelFactory<TChannel> 类
一个创建不同类型通道的工厂,客户端使用这些通道将消息发送到不同配置的服务终结点。
命名空间: System.ServiceModel 语法
public class ChannelFactory<TChannel> : ChannelFactory, IChannelFactory<TChannel>,
IChannelFactory, ICommunicationObject 类型参数
TChannel
由通道工厂生成的通道类型。 此类型必须为 IOutputChannel 或 IRequestChannel。 备注
使用此泛型类可实现一些更高级的方案,在这些方案中有创建通道工厂(可用于创建多个通道类型)的要求。
以编程方式添加行为时,可以在创建任何通道之前将行为添加到 Behaviors 上相应的 ChannelFactory 属性。 有关代码示例,请参见“示例”部分。 /// <summary>
/// 下面的示例演示如何创建通道工厂并用它来创建和管理通道
/// </summary>
public static void Main()
{
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();
} /// <summary>
/// 下面的代码示例演示如何在工厂创建通道对象前,以编程方式插入客户端行为。
/// </summary>
public class Client
{
public static void Main()
{
try
{
// Picks up configuration from the config file.
ChannelFactory<ISampleServiceChannel> factory
= new ChannelFactory<ISampleServiceChannel>("WSHttpBinding_ISampleService"); // Add the client side behavior programmatically to all created channels.
factory.Endpoint.Behaviors.Add(new EndpointBehaviorMessageInspector()); ISampleServiceChannel wcfClientChannel = factory.CreateChannel(); // Making calls.
Console.WriteLine("Enter the greeting to send: ");
string greeting = Console.ReadLine();
Console.WriteLine("The service responded: " + wcfClientChannel.SampleMethod(greeting)); Console.WriteLine("Press ENTER to exit:");
Console.ReadLine(); // Done with service.
wcfClientChannel.Close();
Console.WriteLine("Done!");
}
catch (TimeoutException timeProblem)
{
Console.WriteLine("The service operation timed out. " + timeProblem.Message);
Console.Read();
}
catch (FaultException<SampleFault> fault)
{
Console.WriteLine("SampleFault fault occurred: {0}", fault.Detail.FaultMessage);
Console.Read();
}
catch (CommunicationException commProblem)
{
Console.WriteLine("There was a communication problem. " + commProblem.Message);
Console.Read();
}
}

最新文章

  1. ASP.NET MVC Model绑定(二)
  2. Linux 内核日志——dmesg
  3. Redis的五种数据结构
  4. Libgdx 开发指南(1.1) 应用框架——生命周期
  5. 互联网的寒冬来了,BAT都不社招了
  6. [Design Patterns] 3. Software Pattern Overview
  7. 网站地图sitemap.xml的格式
  8. SQL语句大全(mysql,sqlserver,oracle)
  9. 第六章_PHP数组(二)
  10. Spring.Net的Ioc功能基本配置
  11. sizeof的用法的一些归纳
  12. Java 删除当前文件夹及其文件夹下的全部文件
  13. 我的github代码添加
  14. Mysql group_concat
  15. static wechat red package tool
  16. chrome devtools
  17. HUST 1584 摆放餐桌
  18. IdentityServer(12)- 使用 ASP.NET Core Identity
  19. 数据结构 哈希表(Hash Table)_哈希概述
  20. php error_log() 范例

热门文章

  1. []ARC098
  2. 【三分】Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed
  3. Xcode8 不能显示blame,show blame for line 灰色不可点解决办法
  4. Java使用纯真IP库获取IP对应省份和城市
  5. canvas如何兼容IE8
  6. javascript快速入门13--BOM——浏览器对象模型(Browser Object Model)
  7. 2017.11.15 hashmap的工作原理
  8. 用table表格来调整控件的格式
  9. Windows如何定时关机
  10. Invalid code signing entitlements. Your application bundle&#39;s signature contains