WCF简介-01
WCF Windows Communication Foundation
1.1 新建一个"空白解决方案"
1.2 在解决方案中添加类库IBLL
1.2.1 添加接口IUserInfoService
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks; namespace IBLL
{
[ServiceContract]
public interface IUserInfo
{
[OperationContract]
int Add(int a ,int b);
}
}
IUserInfo
1.2.2 添加引用 System.ServiceModel
1.3 添加类库BLL
1.3.1 添加引用IBLL
1.3.2 添加类UserInfoService实现接口IBLL
using IBLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace BLL
{
public class UserInfoService:IUserInfoService
{
public int Add(int a, int b)
{
return a + b;
}
}
}
UserInfoService
1.4 将WCF布置到控制台程序
1.4.1 添加控制台程序Host
1.4.2 添加引用BLL和IBLL
1.4.3 修改App.config文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="BLL.UserInfoService" behaviorConfiguration="behaviorConfiguration">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/"/>
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding" contract="IBLL.IUserInfoService"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="behaviorConfiguration">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
App.config
1.4.4 添加引用System.ServiceModel
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks; namespace Host
{
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(BLL.UserInfoService)))
{
host.Open();
Console.WriteLine("服务启动成功!");
Console.ReadKey();
}
}
}
}
Main
1.4.5 进入debug目录,以管理员身份启动

1.4.6 启动客户端测试服务程序
VS安装目录下F:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\WcfTestClient.exe

2 客户端程序
2.1 控制台程序-新建控制台程序
F:\Users\home\Documents\Visual Studio 2013\WCFDemo\Solution1\Client
svcutil http://localhost:8000/?wsdl /o:UserInfoServiceClient.cs

2.2 将生成的文件包括到项目中

2.3 勇output.config文件替换掉App.config文件(删App,将output重命名)
2.4 添加引用BLL,IBLL和ServiceModel
2.5 client 中main方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Client
{
class Program
{
static void Main(string[] args)
{
UserInfoServiceClient client = new UserInfoServiceClient();
int sum = client.Add(,);
Console.WriteLine(sum);
Console.ReadKey();
}
}
}
Main
2.6 改造自动生成的
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------ //[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
//[System.ServiceModel.ServiceContractAttribute(ConfigurationName="IUserInfoService")]
//public interface IUserInfoService
//{ // [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IUserInfoService/Add", ReplyAction="http://tempuri.org/IUserInfoService/AddResponse")]
// int Add(int a, int b); // [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IUserInfoService/Add", ReplyAction="http://tempuri.org/IUserInfoService/AddResponse")]
// System.Threading.Tasks.Task<int> AddAsync(int a, int b);
//} using IBLL;
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface IUserInfoServiceChannel : IUserInfoService, System.ServiceModel.IClientChannel
{
} [System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class UserInfoServiceClient : System.ServiceModel.ClientBase<IUserInfoService>, IUserInfoService
{ public UserInfoServiceClient()
{
} public UserInfoServiceClient(string endpointConfigurationName) :
base(endpointConfigurationName)
{
} public UserInfoServiceClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
} public UserInfoServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
} public UserInfoServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
} public int Add(int a, int b)
{
return base.Channel.Add(a, b);
} //public System.Threading.Tasks.Task<int> AddAsync(int a, int b)
//{
// return base.Channel.AddAsync(a, b);
//}
}
UserInfoServiceClient
2.7 分别启动两个exe文件

3 我们也可以自己建立一个客户端
3.1 创键控制台应用程序
3.2 添加服务引用

3.3 运行结果

WCF简介-01的更多相关文章
- WCF学习——WCF简介(三)
一.WCF简介 1.什么是WCF? WCF的全称是:Windows Communication Foundation.从本质上来说,它是一套软件开发包,是微软公司推出的符合SOA思想的技术框架. 2. ...
- 第1章WCF简介(WCF全面解析读书笔记2)
第1章 WCF简介 面向服务架构(SOA)是近年来备受业界关注的一个主题,它代表了软件架构的一种方向.顺应SOA发展潮流,微软于2006年年底推出了一种新的分布式通信框架Windows Communi ...
- WCF全面解析第一章 WCF 简介
1.WCF中的 "A","B","C" 介绍 我们先看个生活中的例子,某一天,公司的领导让你去送一份合同文件,送文件的过程你可以选择的交通方 ...
- WCF简介
WCF(Windows communication Foundation),顾名思义,就是在windows平台下解决通信的基础框架.WCF做为.NET Framework 3.0的一个组件发布出来的, ...
- WCF学习笔记(一):WCF简介
转:http://www.cnblogs.com/wengyuli/archive/2009/11/04/1595693.html MSDN上关于WCF给出如下注解: 设计 Windows Commu ...
- wcf例子01
一.概述 Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分.由 .NE ...
- mysql高可用架构 -> MHA简介-01
作者简介 松信嘉範:MySQL/Linux专家2001年索尼公司入职2001年开始使用oracle2004年开始使用MySQL2006年9月-2010年8月MySQL从事顾问2010年-2012年 D ...
- Redis系列---redis简介01
一. 本章我们将用简短的几句话来帮助你快速的了解什么是redis,初学者不必深究 1 Redis简介 Remote Dictionary Server(Redis)是一个开源的使用ANSI C语言编写 ...
- 小步前进之WCF简介
WCF 前言 什么是WCF? 契约 合约 前言 在 .NET Framework2.0 以及前版本中,微软发展了 Web Service..NET Remoting 等通信支持. 如果要进行通信,对于 ...
随机推荐
- IP路由原理
IP路由原理 一.什么是路由 路由是指导IP报文发送的路径信息. 二.路由表的构成 路由表是路由器转发报文的判断依据 三.路由器单跳操作 四.路由表查找规则 1.选择度量值小的进行转发 2.永远将下一 ...
- FastDFS与Nginx的搭建及遇到的问题
1.1 FastDFS与Nginx的搭建 可以使用一台虚拟机来模拟,只有一个Tracker.一个Storage服务. 配置nginx访问图片. 1.1.1 搭建步骤 第一步:把fastDFS需要 ...
- CSS实现文字竖排排版
CSS实现文字竖排 注意: writing-mode: vertical-rl;存在兼容性问题,在IE上正常,在谷歌的低版本上可能识别不了. 如果文字少的话考虑直接在每一个文字中间加一个<br& ...
- Html-Css 从入门到放弃(一)基础知识
注意要点: 1.ID属性不要以数字开头,数字开头的ID在 Mozilla/Firefox 浏览器中不起作用. 2.class 选择器用于描述一组元素的样式,class 选择器有别于id选择器,clas ...
- 流媒体技术学习笔记之(一)nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器
参照网址: [1]http://blog.csdn.net/redstarofsleep/article/details/45092147 [2]HLS介绍:http://www.cnblogs.co ...
- android kotlin Gradle DSL method not found: '1.2.51()'错误,be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
同步的时候遇到这个问题,从log上看是因为gradle的版本不包含kotlin 1.2.51这个method,具体原因我也不是很清楚,大概猜测是kotlin版本的问题,而最新的版本就是1.2.51,所 ...
- elementUI 表格设置表头样式
eader-row-class-name 表头行的 className 的回调方法,也可以使用字符串为所有表头行设置一个固定的 className. Function({row, rowIndex}) ...
- 《Two Dozen Short Lessons in Haskell》所有习题的索引
<Two Dozen Short Lessons in Haskell>(Copyright © 1995, 1996, 1997 by Rex Page,有人翻译为Haskell二十四学 ...
- java先导课程学习总结
经过两个星期四节课的java学习,我也对java这门语言有了一定的认识.刚开始上课的时候,我认为java把C语言中老师所说的模块化编程进行了强调,进行一个类,一个类的编程,在类中构造相应的方法,使用的 ...
- mysql 案例 ~ pt校验工具介绍
简介:今天咱们来聊聊PT校验工具pt-table-checksum 注意事项: 1. 根据测试,需要一个即能登录主库,也能登录从库的账号: 2. 只能指定一个host,必须为主库的IP: ...