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服务提供一个运行的环境.通过为服务添加一个或者多个终结点,使之暴露给潜在的服务消费,服务消费者通过匹配的终结点对该服务进行调用,除去上面的两种寄宿方式,还可以 ...
随机推荐
- Python__for循环和列表生成式的区别
话不多,上例子 >>> L = [,,] >>> for i in range(len(L)): L[i] = L[i] + L[i-] print(L) #结果 ...
- list函数及list对象的reverse方法
list的reverse方法,是就地reverse,不返回值 如a是一个list,a.reverse()直接将a这个list给reverse了,所以如果print(a.reverse())就是None ...
- IAR 编译时找不到头文件的解决方法
Fatal Error[Pe1696]: cannot open source file "x.h" 那是因为头文件路径没有找对 到报错的.c源文件 选中右键 选择options ...
- get请求中url传参中文乱码问题
在项目中经常会遇到中文传参数,在后台接收到乱码问题.那么在遇到这种情况下我们应该怎么进行处理让我们传到后台接收到的参数不是乱码是我们想要接收的到的,下面就是我的一些认识和理解. 一:get请求url中 ...
- 如何在 Eclipse 中使用插件构建 PHP 开发环境[转]
原文出处: http://hykloud.com/2012/03/08/information_technology/how-setup-eclipse-php-pdt-remote-system-e ...
- 《Cracking the Coding Interview》——第12章:测试——题目6
2014-04-25 00:53 题目:你要如何测试一个分布式银行系统的ATM机? 解法:ATM是Automatic Teller Machine,取钱的.我想了半天,没找到什么很清晰的思路,也许是因 ...
- ajax向Asp.NET后端传递数组型数据
近日,在开发一个组件的过程中,需要通过Ajax对象向Asp.NET后端传递一个比较复杂的表单,表单中的一个字段是数组类型,我能想到的办法是用JSON.stringify将前端的数组对象序列化成字符串, ...
- 孤荷凌寒自学python第四十七天通用跨数据库同一数据库中复制数据表函数
孤荷凌寒自学python第四十七天通用跨数据库同一数据库中复制数据表函数 (完整学习过程屏幕记录视频地址在文末) 今天继续建构自感觉用起来顺手些的自定义模块和类的代码. 今天打算完成的是通用的(至少目 ...
- ssh.sh_for_ubuntu1204
#!/bin/bash sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config s ...
- Day2 Activity生命周期/启动模式/最佳实践
Android是使用任务(Task)来管理活动的,这个栈被称作返回栈(Back Stack). Activity类中定义了7个回调方法: onCreate().在活动第一次被创建时调用,应该在这个方法 ...