一个简单的wcf实现
2012-06-18 21:32
211 查看
打开vs2010,新建项目如图
![](http://pic002.cnblogs.com/images/2012/376147/2012061821201997.png)
添加新建项目
![](http://pic002.cnblogs.com/images/2012/376147/2012061821232267.png)
![](http://pic002.cnblogs.com/images/2012/376147/2012061821251277.png)
添加服务引用
![](http://pic002.cnblogs.com/images/2012/376147/2012061821265697.png)
![](http://pic002.cnblogs.com/images/2012/376147/2012061821273544.png)
添加新建项webform.aspx
webform.aspx.cs
wcf项目里的IService1.cs
Services1.svc.cs
以上就是我的第一个wcf应用程序
![](http://pic002.cnblogs.com/images/2012/376147/2012061821290918.png)
点此下载相关代码
![](http://pic002.cnblogs.com/images/2012/376147/2012061821201997.png)
添加新建项目
![](http://pic002.cnblogs.com/images/2012/376147/2012061821232267.png)
![](http://pic002.cnblogs.com/images/2012/376147/2012061821251277.png)
添加服务引用
![](http://pic002.cnblogs.com/images/2012/376147/2012061821265697.png)
![](http://pic002.cnblogs.com/images/2012/376147/2012061821273544.png)
添加新建项webform.aspx
<div> <p><asp:TextBox ID="chuancan" runat="server"></asp:TextBox><asp:Button ID="btn_ok" runat="server" Text="提交" onclick="btn_ok_Click" /></p> <p> <asp:Label ID="showtext" runat="server" Text=""></asp:Label></p> </div>
webform.aspx.cs
protected void btn_ok_Click(object sender, EventArgs e) { ServiceReference1.Service1Client client = new ServiceReference1.Service1Client(); showtext.Text = client.HelloWorld(chuancan.Text.Trim().ToString()); }
wcf项目里的IService1.cs
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; namespace WcfService1 { // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IService1”。 [ServiceContract] public interface IService1 { [OperationContract] string GetData(int value); [OperationContract] CompositeType GetDataUsingDataContract(CompositeType composite); // TODO: 在此添加您的服务操作 [OperationContract] string HelloWorld(string user);//自己添加的一个方法 } // 使用下面示例中说明的数据约定将复合类型添加到服务操作。 [DataContract] public class CompositeType { bool boolValue = true; string stringValue = "Hello "; [DataMember] public bool BoolValue { get { return boolValue; } set { boolValue = value; } } [DataMember] public string StringValue { get { return stringValue; } set { stringValue = value; } } } }
Services1.svc.cs
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; namespace WcfService1 { // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“Service1”。 public class Service1 : IService1 { public string GetData(int value) { return string.Format("You entered: {0}", value); } public CompositeType GetDataUsingDataContract(CompositeType composite) { if (composite == null) { throw new ArgumentNullException("composite"); } if (composite.BoolValue) { composite.StringValue += "Suffix"; } return composite; } public string HelloWorld(string user) { return "你好," + user + "!"; } } }
以上就是我的第一个wcf应用程序
![](http://pic002.cnblogs.com/images/2012/376147/2012061821290918.png)
点此下载相关代码
相关文章推荐
- 利用WCF的双工通讯实现一个简单的心跳监控系统
- 无配置WCF客户端的一个简单到令人发指的实现方法
- 利用WCF的双工通讯实现一个简单的心跳监控系统 z
- 综合应用WPF/WCF/WF/LINQ之三十八:实现一个简单的DataGrid之总体介绍
- 综合应用WPF/WCF/WF/LINQ之三十九:实现一个简单的DataGrid之获取某格的原始(或当前)行(或列)的Index
- 重温WCF之构建一个简单的WCF(一)(2)通过Windows Service寄宿服务和WCF中实现操作重载
- 最简单的一个WCF实现客户端和服务端
- 综合应用WPF/WCF/WF/LINQ之四十:实现一个简单的DataGrid之CheckBox已勾选的项的保存
- 创建一个简单的restful wcf, 并且用silverlight做为客户端实现get, post, put,delete
- 利用xmlHttp实现一个简单的Ajax无刷新
- 一个简单的倒计时控件的实现
- live555 实现一个最简单的RTSP服务器
- 注入框架实践,简单实现一个类似于butterknife的注入框架
- 实现一个简单的服务端推送方案-实例篇Polling
- 【Android游戏开发十六】Android Gesture之【触摸屏手势识别】操作!利用触摸屏手势实现一个简单切换图片的功能!
- <C语言>如何一步一步根据简单的代码联想到更多的功能?(实现输入一个整数,输出比它小包括它本身的所有素数。)
- 在iOS上实现一个简单的日历控件
- 使用Unity3D的设计思想实现一个简单的C#赛车游戏场景
- C语言实现一个简单的服务器
- 一个简单的本地化资源管理系统--具体实现