【转载】WCF入门级使用教程
2008-11-22 11:19
531 查看
开发环境:vs2008英文版(SP1) + IIS + Windows2003
整个解决方案有4个项目
01.WCF ---Class Libary项目,用于生成WCF所需的类/接口文件
02.BLL ---Class LIbary项目,演示用的业务逻辑层(仅做分层演示用,无实际意义)
03.WEB ---Web Application,WCF服务将发布在这个项目中(即本例是把WCF宿主在IIS里)
04.Client--Console Application,命令行程序,用于演示调用WCF的客户端程序
using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Runtime.Serialization;
5using System.ServiceModel;
6using System.Text;
7
8namespace WCF
9using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Runtime.Serialization;
5using System.ServiceModel;
6using System.Text;
7
8namespace WCF
9using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace BLL
7
2<system.serviceModel>
3 <behaviors>
4 <serviceBehaviors>
5 <behavior name="WEB.DemoServiceBehavior">
6 <serviceMetadata httpGetEnabled="true"/>
7 <serviceDebug includeExceptionDetailInFaults="false"/>
8 </behavior>
9 </serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ICalculateService">
<security mode="None">
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="WEB.DemoServiceBehavior" name="WCF.CalculateService">
<endpoint address="wcf" binding="wsHttpBinding" contract="WCF.ICalculateService" bindingConfiguration="WSHttpBinding_ICalculateService" name="WCF.ICalculateService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
7.WCF在IIS里的配置
iis里新建一个站点,指向WEB项目所在的目录,端口在本例中设置为90,如果在浏览器直接浏览http://localhost:90/WCF/CalculateService.svc,表明IIS的环境没问题,如果不行,建议重新安装.net framework3.5(当然也有其它办法,就是增加svc后缀的映射,这个百度一下N多,就不重复了)
8.刚才的WEB项目里,应该还有一个Default.aspx的页面,这里我们简单示例一下调用BLL层代码(Default.aspx.cs内容)
namespace WEB
2using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace ConsoleTest
7
调用真的很简单吧,好了,总结一下:
本例中,先编写了一个简单的WCF服务,然后把它宿主在IIS中运行,然后用控制台程序来调用这个WCF.
当然WCF深入研究下去,远比这个复杂,这篇文章主要是为了消除大家对新技术的恐惧,快速上手WCF的使用,其实MS每次推出的新技术,听上去蛮吓人,用起来都很简单的.
(转载来自"菩提树下的杨过")
整个解决方案有4个项目
01.WCF ---Class Libary项目,用于生成WCF所需的类/接口文件
02.BLL ---Class LIbary项目,演示用的业务逻辑层(仅做分层演示用,无实际意义)
03.WEB ---Web Application,WCF服务将发布在这个项目中(即本例是把WCF宿主在IIS里)
04.Client--Console Application,命令行程序,用于演示调用WCF的客户端程序
using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Runtime.Serialization;
5using System.ServiceModel;
6using System.Text;
7
8namespace WCF
9using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Runtime.Serialization;
5using System.ServiceModel;
6using System.Text;
7
8namespace WCF
9using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace BLL
7
2<system.serviceModel>
3 <behaviors>
4 <serviceBehaviors>
5 <behavior name="WEB.DemoServiceBehavior">
6 <serviceMetadata httpGetEnabled="true"/>
7 <serviceDebug includeExceptionDetailInFaults="false"/>
8 </behavior>
9 </serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ICalculateService">
<security mode="None">
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="WEB.DemoServiceBehavior" name="WCF.CalculateService">
<endpoint address="wcf" binding="wsHttpBinding" contract="WCF.ICalculateService" bindingConfiguration="WSHttpBinding_ICalculateService" name="WCF.ICalculateService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
7.WCF在IIS里的配置
iis里新建一个站点,指向WEB项目所在的目录,端口在本例中设置为90,如果在浏览器直接浏览http://localhost:90/WCF/CalculateService.svc,表明IIS的环境没问题,如果不行,建议重新安装.net framework3.5(当然也有其它办法,就是增加svc后缀的映射,这个百度一下N多,就不重复了)
8.刚才的WEB项目里,应该还有一个Default.aspx的页面,这里我们简单示例一下调用BLL层代码(Default.aspx.cs内容)
namespace WEB
2using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace ConsoleTest
7
调用真的很简单吧,好了,总结一下:
本例中,先编写了一个简单的WCF服务,然后把它宿主在IIS中运行,然后用控制台程序来调用这个WCF.
当然WCF深入研究下去,远比这个复杂,这篇文章主要是为了消除大家对新技术的恐惧,快速上手WCF的使用,其实MS每次推出的新技术,听上去蛮吓人,用起来都很简单的.
(转载来自"菩提树下的杨过")
相关文章推荐
- [原创]WCF入门级使用教程(转载请注明出处)
- [原创]WCF入门级使用教程(转载请注明出处)
- wcf入门教程之在.net471中创建一个使用tcp网络协议的wcf控制台开发测试环境
- WCF入门教程一[什么是WCF]--转载只为学习收藏
- 转载:Postman 安装及使用入门教程
- <转载>ant使用指南详细入门教程 http://www.jb51.net/article/67041.htm
- svm 简单明了的入门级使用教程(转载)
- wcf入门教程之在.net471中创建一个使用tcp网络协议的wcf windows服务进程
- 【转载】MSDN上发现了一篇很好的WCF入门教程
- jQueryUI Autocomplete插件使用入门教程(最新版)---------转载
- (转载)directshow的下载、VC2008中的配置、入门教程以及如何在opencv中使用
- 【转载】图灵AngularJS入门教程
- 使用jQuery Mobile框架开发移动端Web App的入门教程
- 使用github实现共享代码的一些入门级教程
- WPF入门教程系列(二) 深入剖析WPF Binding的使用方法
- 转载一份:【超详细教程】使用Windows Live Writer 2012和Office Word 2013 发布文章到博客园全面总结
- IDEA入门级使用教程
- 【转载】Flexpaper二次开发入门教程(ajava.org发布)[PDF]
- wcf系列学习5天速成——第三天 事务的使用(转载)
- 【Github教程】史上最全github使用方法:github入门到精通之一