欢迎来到天天文库
浏览记录
ID:37908260
大小:78.57 KB
页数:9页
时间:2019-06-02
《WCF三种Binding》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、http://www.mybdqn.cn/北大青鸟上地软件园:WCF三种Binding 转眼wcf技术已经出现很多年了,也在.net界混的风生水起,同时.net也是一个高度封装的框架,作为在wcf食物链最顶端的我们所能做的任务已经简单的不能再简单了,再简单的话马路上的大妈也能写wcf了,好了,wcf最基本的概念我们放在后面慢慢分析,下面我们来看看北大青鸟上地软件园神奇的3个binding如何KO我们实际场景中的80%的业务场景。 一:basicHttpBinding 作为入门第一篇,也就不深入谈谈basic中的信道栈中那些啥东西了,你只需要知道有ABC三个要素,注意不是姨妈巾哦,
2、如果需要详细了解,可以观赏我以前的系列。在这里我就不多说了,太简单的东西没意思,先看个例子简单感受了,你只需知道的是basic走的是http协议就好了,传输消息为soap。1.契约1usingSystem.Runtime.Serialization;2usingSystem.ServiceModel;34namespaceMyService5{6[ServiceContract]7publicinterfaceIHomeService8{9[OperationContract]10intGetLength(stringname);11}12}2.实现类1usingSystem;2us
3、ingSystem.Messaging;http://www.mybdqn.cn/3usingSystem.Threading;45namespaceMyService6{7publicclassHomeService:IHomeService8{9publicintGetLength(stringname)10{11returnname.Length;12}13}14}3.服务启动1usingSystem;2usingSystem.ServiceModel;34namespaceMyService5{6classProgram7{8staticvoidMain(string[]ar
4、gs)9{10using(ServiceHosthost=newServiceHost(typeof(HomeService)))11{12try13{14host.Open();1516Console.WriteLine("服务开启!");1718Console.Read();19}20catch(Exceptione)21{22Console.WriteLine(e.Message);23}24}25}http://www.mybdqn.cn/26}27}4.配置config文件
5、6、es>7、ddresses>http://www.mybdqn.cn/5.然后通过servicehost启动服务端usingSystem;usingSystem.ServiceModel;namespaceMyService
6、es>7、ddresses>http://www.mybdqn.cn/
7、ddresses>
此文档下载收益归作者所有