WCFRestFull空框架,套上业务逻辑实现就可以用了

            几年前做后台业务逻辑开发,有幸接触了Wcf,今天有朋友请教wcf的问题,我抽空弄了个空的框架。

          说明:

           1  有windows 服务的项目

           2  业务类都基于Base基类

          3  使用log4net 做日志记录处理

          4 同时使用了wcf的自带日志

          5 实现自动更新终结点配置

        

      接口中的定义类似如下:

     

 /// <summary>
    ///数据InterFace
    /// </summary>
    [ServiceContract]
    public interface ITest
    {
        /// <summary>
        ///获得One
        /// </summary>
        /// <param name="id">人员id</param>
        /// <returns></returns>
        [WebGet(UriTemplate = "GetOne?id={id}",
         ResponseFormat = WebMessageFormat.Json)]
        Student GetOne(Int64 id);
        /// <summary>
        ///获得所有
        /// </summary>
        /// <param name="id">人员id</param>
        /// <returns></returns>
        [WebGet(UriTemplate = "GetAllByClassName?className={className}",
         ResponseFormat = WebMessageFormat.Json)]
        List<Student> GetAllByClassName(string className);
        
        /// <summary>
        ///添加
        /// </summary>
        /// <param name="AnnexDtO"></param>
        /// <returns></returns>
        [WebInvoke(UriTemplate = "Add", Method = "PUT", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        bool Add(Student student);
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="DataValue"></param>
        /// <returns></returns>
        [WebInvoke(UriTemplate = "Edit", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        bool Edit(Student student);
        /// <summary>
        ///根据Id进行删除
        /// </summary>
        /// <param name="id">要删除的ID</param>
        /// <returns>状态及结果</returns>
        [WebInvoke(UriTemplate = "Del", Method = "DELETE", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        bool Del(Int64 id);
    }
     接口实现如下,因为时间问题 没有做详细的业务逻辑实现说明,见谅

     

 /// <summary>
    ///service 实现
    /// </summary>
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class TestService : Base, ITest
    {
        /// <summary>
        ///
        /// </summary>
        public TestService()
        {

        }

        #region ITest 成员

        public Student GetOne(long id)
        {
            return new Student { ID = 1, Age = 24, ClassName = "计算机4班", Name = "张三" };
        }

        public List<Student> GetAllByClassName(string className)
        {
            List<Student> list = new List<Student>();  //业务实现 ...
            return list;
        }

        public bool Add(Student student)
        {
             //业务实现
            return true;
        }

        public bool Edit(Student student)
        {
            //业务实现
            return true;
        }

        public bool Del(long id)
        {
            //业务实现
            return true;
        }

        #endregion
    }
   其它配置参考app.config中,注意如果使用window 服务,需要将最新的业务实现项目中app.config拷贝到 windows服务中的config中!

  下载请到 http://download.csdn.net/detail/asa_jim/9087085

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凌晨4点5杀老大爷

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值