wcf能完成分布式应用程序。
构建方式可以通过标准类库或者wcf项目模板。
整个wcf一般会创建3个程序集
① wcf服务程序集: *dll文件,包含了希望向外部用户公开的整体功能的类和接口。
②wcf 服务宿主: HOST模块,承载了wcf服务程序集的实体。
③wcf 客户端: 通过中间代理访问服务功能的应用程序。
首先学习通过最麻烦最细节的方式来做。
第一步:
新创建一个class lib,修改项目名字MagicEightBallServiceLib。
添加system.servicemodel应用。

using System;
using System.ServiceModel;
namespace MagicEightBallServiceLib
{
public class MagicEightBallService:IEightBall
{
public MagicEightBallService()
{
Console.WriteLine("8个球等待你的问题。。。");
}
public string obtainAnswerToQueston(string userQuestion)
{
string[] answers = { "future uncertain","yes","no","hazy","ask again later","definitely"};
//返回随机响应
Random r = new Random();
return answers[r.Next(answers.Length)];
}
}
[ServiceContract]
1796



被折叠的 条评论
为什么被折叠?



