您的位置:首页 > 其它

一个简单的WCF实例

2010-10-25 21:32 218 查看
在学习WCF的相关知识,写了一个非常简单的例子。

项目结构如下:



Super.Wdxt.School.Contract 类库程序,定义服务契约(主要是一些接口),引用Super.Wdxt.School.Entity ;

Super.Wdxt.School.Entity 类库程序,一些实体

Super.Wdxt.School.Services 类库程序,提供对WCF服务的实现,也就是Contract项目中的接口实现类,引用Super.Wdxt.School.Entity,Super.Wdxt.School.Contract 。

Super.Wdxt.School.Hosting WEB应用程序,WCF的宿主程序,你可以使用不同的宿主程序比如控制台,winForm等等。引用上面三项.

Super.Wdxt.School.Web WEB应用程序,客户端程序。

1.创建实体类UserInfo.cs

记得添加引用   using System.ServiceModel;  using System.ServiceModel.Web;



删除其.cs文件,更改User.svc如下:

<%@ ServiceHost Language="C#" Debug="true" Service="Super.Wdxt.School.Services.User" CodeBehind="Super.Wdxt.School.Services.User.cs" %>


更改Web.config中system.serviceModel节点如下:


4.Super.Wdxt.School.Web 中选择添加服务--点击发现



确定。在Default后台页面使用如下:

using (ServiceReference1.UserClient obj = new Super.Wdxt.School.Web.ServiceReference1.UserClient())
{
string aa = obj.GetName(1);

Response.Write(aa);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: