• 创Wcf案例数据服务


    首先,创建实体类:

    using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.Data.Services.Common;

    namespace Net.Wcf.WebApplication
    {
        [DataServiceKey("Id")]
        public class Student
        {
            public string Id { get; set; }
            public string Name { get; set; }

            public Student() { }

            public Student(string id,string name) {
                this.Id = id;
                this.Name = name;
            }
        }

        [DataServiceKey("Id")]
        public class Teacher
        {
            public string Id { get; set; }
            public string Name { get; set; }

            public Teacher() { }

            public Teacher(string id, string name)
            {
                this.Id = id;
                this.Name = name;
            }
        }
    }

    创建提供数据服务类:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    namespace Net.Wcf.WebApplication
    {
        public class DataServiceModel
        {
            #region 方法
            public IQueryable<Student> Students {
                get {
                    return GetAllStudents().AsQueryable();
                }
            }

            public IQueryable<Teacher> Teachers
            {
                get
                {
                    return GetAllTeachers().AsQueryable();
                }
            }

            #endregion

            #region 提供数据
            private List<Student> GetAllStudents() {
                return new List<Student>() {
                  new Student("1","刘备"),new Student("2","关羽"),new Student("3","张飞"),new Student("4","赵云"),
                  new Student("5","曹操"),new Student("6","周瑜"),new Student("7","孙权"),new Student("8","司马懿"),

                };
            }

            private List<Teacher> GetAllTeachers()
            {
                return new List<Teacher>() {
                  new Teacher("1","李世民"),new Teacher("2","赵匡胤"),new Teacher("3","赵构"),new Teacher("4","岳飞"),
                  new Teacher("5","朱元璋"),new Teacher("6","朱棣"),new Teacher("7","乾隆"),new Teacher("8","蒋介石"),

                };
            }
            #endregion
        }
    }

    配置服务:

    公布服务,就能够在浏览器查看了。

    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    常用英语口语绝佳句型100句
    Mac Keyboard Shortcuts
    Linux中.a,.la,.o,.so文件的意义和编程实现
    走近GCC 4——GCC 4新特性揭秘(转)
    python 中移去文件的只读属性
    写给金融危机下毕业生的16条忠告
    C++中如何强制inline函数(MSVC, GCC)
    #pragma hdrstop
    富人和穷人的差别(转)
    商业周刊评出08年增长最快的美国科技公司
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4891720.html
Copyright © 2020-2023  润新知