WCF信道绑定代码
监听端创建信道Listener,代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels; namespace Artech.MessagingVisBinding.Listener
{
class Program
{
static void Main(string[] args)
{
Uri listenUri = new Uri("http://127.0.0.1:9999/listener");
Binding binding = new BasicHttpBinding();
IChannelListener<IReplyChannel> channelListener = binding.BuildChannelListener<IReplyChannel>(listenUri);
channelListener.Open();
IReplyChannel channel = channelListener.AcceptChannel(TimeSpan.MaxValue);
channel.Open();
Console.WriteLine("开始监听。。。");
while (true)
{
RequestContext requestContext = channel.ReceiveRequest(TimeSpan.MaxValue);
Console.WriteLine("接受到请求信息:\n{0}",requestContext.RequestMessage);
requestContext.Reply(CreateReplyMessage(binding));
}
} static Message CreateReplyMessage(Binding binding)
{
string action = "urn:artech.com/reply";
string body = "这是一个简单的回复消息!";
return Message.CreateMessage(binding.MessageVersion, action, body);
}
}
}
发送端创建信息Sender,代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Channels;
using System.ServiceModel; namespace Artech.MessagingViaBinding.Sender
{
class Program
{
static void Main(string[] args)
{
Uri listenUri = new Uri("http://127.0.0.1:9999/listener");
Binding binding = new BasicHttpBinding();
IChannelFactory<IRequestChannel> channelFactory = binding.BuildChannelFactory<IRequestChannel>();
channelFactory.Open();
IRequestChannel channel = channelFactory.CreateChannel(new EndpointAddress(listenUri));
channel.Open();
Message replyMessage = channel.Request(CreateRequestMessage(binding));
Console.WriteLine("接收到的消息\n{0}", replyMessage); Console.Read();
} static Message CreateRequestMessage(Binding binding)
{
string action = "urn:artech.com/request";
string body = "这是一个简单的请求消息!";
return Message.CreateMessage(binding.MessageVersion, action, body);
}
}
}
WCF信道绑定代码的更多相关文章
- WCF入门(八)---WCF服务绑定
WCF服务绑定是一个集合,每个元素定义了服务与客户端进行通信方式的几个元素.传输元素和一个消息编码元素各自结合两个最重要的组成部分.这里是WCF服务绑定常用的列表. 基础绑定 基础约束是由basicH ...
- WCF基础:绑定(三)
在WCF绑定体系中,绑定创建绑定元素,绑定元素创建绑定监听器/绑定工厂,绑定监听器/绑定工厂创建信道. WCF中绑定是有多个信道相连组成的信道栈,在这个信道栈中必须包含传输信道和编码信道,而且传输信道 ...
- WCF基础:绑定(一)
WCF中的终结点(ServiceEndpoint)包含有三要素:地址(EndpointAddress),绑定(Binding),契约描述(ContractDescription)三要素:其中绑定的在整 ...
- JS事件调试 - 查找HTML元素绑定的事件以及绑定代码所在位置
日常的网页开发调试工作中,经常需要知道指定的某个网页元素绑定了哪些事件以及绑定代码的位置,下面介绍三种用来跟踪页面中的事件的方法. 1.使用firefox调试 我们可以使用firefox的debug工 ...
- WCF基础:绑定(二)
在WCF的绑定体系中,经常会碰到ICommunicationObject接口,无论是IChannel接口还是IChannelListener/IChannelFactory接口都继承了ICommuni ...
- WCF之绑定
NameSpace+Name作为服务元数据的唯一标示.BindingElement描述Binding的特征. 绑定表示通信信道的配置,定义C/S间的协议. 分为:传输信道(TCP,HTTP…),消息编 ...
- [WCF]缺少一行代码引发的血案
这是今天作项目支持的发现的一个关于WCF的问题,虽然最终我只是添加了一行代码就解决了这个问题,但是整个纠错过程是痛苦的,甚至最终发现这个问题都具有偶然性.具体来说,这是一个关于如何自动为服务接口(契约 ...
- silverlight 生成图表 WCF 解析XML代码.svc.cs 文件
silverlight 调用wcf 文件代码 private ListItem AnalyzeXML(string XMLCode, string Reportdate, string ChartNa ...
- WCF使用纯代码的方式进行服务寄宿
服务寄宿的目的是为了开启一个进程,为WCF服务提供一个运行的环境.通过为服务添加一个或者多个终结点,使之暴露给潜在的服务消费,服务消费者通过匹配的终结点对该服务进行调用,除去上面的两种寄宿方式,还可以 ...
随机推荐
- bash:/usr/bin/mogod/:connot execute binary:exec fotmat error
前两天博主在安装mogodb的时候出现以下错误,很是郁闷,明明按照教程里面做的,怎么到最后 执行命令的时候出错了呢,以下为错误execute binary:exec fotmat error" ...
- C语言基础篇(二)运算符
导航: 2.1 算数运算符 2.2 逻辑运算符 2.3 位运算 2.4 赋值运算 2.5 内存访问符号 ----->x<------------->x<------------ ...
- PHP.27-TP框架商城应用实例-后台4-使用Gii生成品牌表的代码
Gii安装[GII适用于商城项目] 将Gii文件夹复到application 是,访问http://xx.com/index.php/gii Gii规则[Gii使用规则与建表规则密切相关] 1.建表字 ...
- Spring---BeanFactory与ApplicationContext简介
BeanFactory概念 Spring通过一个配置文件描述bean和bean之间的依赖关系,然后利用java语言的反射功能实例化bean,并建立bean之间的依赖关系.Spring的IOC容器在完成 ...
- Win Server 8中的利器:微软在线备份服务
微软在Windows Server 8中添加在线备份服务了?你一定以为我在开玩笑,是吧?但是微软确实这么做了. 微软在Windows Server 8中添加在线备份服务了?你一定以为我在开玩笑 ...
- CenOS 配置C/C++语言
1.下载eclipse+CDT组合包. 2.电脑上安装GCC, G++ 3.在eclipse上创建一个C++ project 4. Eclipse CDT功能很强大,安装完虽然可以编译运行c++程序, ...
- USACO Section1.5 Superprime Rib 解题报告
sprime解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...
- wxPython 安装 及参考文档
三种操作平台上的安装方法 1.windows 和 mac pip install -U wxPython 2.linux pip install -U -f https://extras.wxpyth ...
- crmsh语法
.查看配置信息 crm(live)# configure crm(live)configure# show node node1 node node2 property cib-bootstrap-o ...
- ironic images
参考: http://blog.csdn.net/wanghuiict/article/details/52757359 ironic 整个部署流程中有两组映像,分别是 deploy 映像和 user ...