WCF REST简单应用 编程初始化 help页面实现
2015-10-13 11:17
323 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; using System.ServiceModel.Web; using YFmk.Models.Web; namespace SmartServiceBLL { /// <summary> /// WCF 服务接口 /// </summary> [ServiceContract] public interface ISmartService { #region 餐饮刷卡 /// <summary> /// 获取所有餐厅区域 /// </summary> /// <returns></returns> [OperationContract] [WebInvoke( UriTemplate = "Refectory/GetRefectoryList", Method = "GET", ResponseFormat = WebMessageFormat.Json )] OPResult GetRefectoryList(); #endregion } }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Newtonsoft.Json;
using YFmk.ORM;
using YFmk.Models.Web;
namespace SmartServiceBLL
{
/// <summary>
/// WCF服务
/// </summary>
internal class SmartService : ISmartService
{
#region 餐饮刷卡
#endregion
#region ISmartService 成员
/// <summary>
/// 获取所有餐厅区域
/// </summary>
/// <returns></returns>
public OPResult GetRefectoryList()
{
OPResult nOPResult=new OPResult();
List<MiniModels.Area> nList = new DAL<MiniModels.Area>().GetList("AreaType=2", "AreaName ASC", null);
if (nList.Count > 0)
{
nOPResult.Result = true;
nOPResult.rows = JsonConvert.SerializeObject(nList);
}
else
{
nOPResult.Result = false;
nOPResult.Data = "服务端未配置任何餐厅信息";
}
return nOPResult;
}
#endregion
}
}
编码实现WCF REST初始化,并提供help服务说明页面。
Uri httpBaseAddress = new Uri("http://localhost:8000"); WebServiceHost mServiceHost = new WebServiceHost(typeof(SmartService), httpBaseAddress); Binding nWebHttpBinding = new WebHttpBinding(); mServiceHost.AddServiceEndpoint(typeof(ISmartService), nWebHttpBinding, "SmartService"); WebHttpBehavior helpBehavior = new WebHttpBehavior(); helpBehavior.HelpEnabled = true; mServiceHost.Description.Endpoints[0].Behaviors.Add(helpBehavior); mServiceHost.Open();
示例URL:http://localhost:8000/SmartService/help
相关文章推荐
- 一个由Django的save方法引发的bug
- ASP.Net MVC 给母版页视图传递数据
- 浅谈Java中的hashcode方法
- SystemUI源码提取到eclipse中编译
- java swing 窗口界面关闭事件响应
- 项目需求将上传的文件统一FTP传送到一个服务器
- github不错的
- Struts2
- PHP上传图片文件
- C# VS2012下的3D显示(一)
- C#编程自学之运算符和表达式
- Webform中Repeater控件--绑定嵌入C#代码四种方式
- java中的hashcode()和equals()
- python导入txt文件并绘制成条形图
- Java基础——数组的使用
- c/c++ int _tmain(int argc, _TCHAR* argv[])
- 基于Spring4的全注解实现Restful开发
- python os 模块
- Gradle 笔记——Java构建入门
- PHP上传图片到独立的图片服务器