zoukankan      html  css  js  c++  java
  • 创建WCF数据服务

    1.创建asp.net web应用程序,并以NorthwindDataService命名

    2.新建ADO.NET 实体模型,并以Northwind.edmx命名

    3.下载事例数据库NORTHWND http://www.microsoft.com/en-us/download/details.aspx?id=23654 并附加到数据库

    4.配置ado.net 的数据库连接到刚下的那个数据库上

    新建连接

    根据自己的数据库添加数据库连接

    配置完连接后,下一步

    选中要包括的对象

    完成

    5.创建数据服务

    6.替换服务中的实体容器
                    
    			
    在edmx中查看其名字
    


    public class Northwind : DataService<NorthwindEntities>
    7.启用对数据服务的访问 
    			

    修改Northwind.svc.cs中的函数

    public static void InitializeService(DataServiceConfiguration config)

    {

    // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.

    // Examples:

    // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);

    // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);

    config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;

    // Grant only the rights needed to support the client applications.

    config.SetEntitySetAccessRule("Orders", EntitySetRights.AllRead

    | EntitySetRights.WriteMerge

    | EntitySetRights.WriteReplace);

    config.SetEntitySetAccessRule("Order_Details", EntitySetRights.AllRead

    | EntitySetRights.AllWrite);

    config.SetEntitySetAccessRule("Customers", EntitySetRights.AllRead);

    config.SetEntitySetAccessRule("Products", EntitySetRights.AllRead

    | EntitySetRights.WriteReplace);

    }

    这使授权客户端能够访问三个指定实体集的资源。

    其中Orders、Order_Details、Customers、Products是位于实体类容器中的内部类属性

    参考ASP.NET 安全性:http://msdn.microsoft.com/zh-cn/library/windowsphone/develop/91f66yxt(v=vs.95).aspx

    8.在Web浏览器中测试服务

    在 Internet Explorer 的"工具"菜单上选择"Internet 选项",单击"内容"选项卡,再单击"源"部分的"设置",然后清除"打开源阅读视图"。

    这可确保禁用源阅读。 如果不禁用此功能,则 Web 浏览器会将返回的 AtomPub 编码文档视为 XML 源,而不显示原始 XML 数据。

    按F5调试

    打开http://localhost:[端口号]/northwind.svc 返回默认服务文档,其列出了此数据服务公开的的实体类。只有为读取访问而显式启用的实体集才会返回。

    输入 http://localhost:[端口号]/northwind.svc/Customers('ALFKI')/Orders这将遍历客户和订单之间的关系以返回特定客户 ALFKI 的所有订单的集合。

    URI规则参考:访问数据服务资源(WCF 数据服务)http://msdn.microsoft.com/zh-cn/library/dd728283.aspx

    作者:王春明 出处:http://wangchunming.cnblogs.com/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    49. 字母异位词分组
    73. 矩阵置零
    Razor语法问题(foreach里面嵌套if)
    多线程问题
    Get json formatted string from web by sending HttpWebRequest and then deserialize it to get needed data
    How to execute tons of tasks parallelly with TPL method?
    How to sort the dictionary by the value field
    How to customize the console applicaton
    What is the difference for delete/truncate/drop
    How to call C/C++ sytle function from C# solution?
  • 原文地址:https://www.cnblogs.com/wangchunming/p/3035721.html
Copyright © 2011-2022 走看看