php 访问wcf服务器,从 Web 浏览器访问服务(WCF 数据服务快速入门)

从 Web 浏览器访问服务(WCF 数据服务快速入门)Accessing the Service from a Web Browser (WCF Data Services Quickstart)

03/30/2017

本文内容

重要

WCF Data Services 已被弃用,并且将不再可从 Microsoft 下载中心下载。WCF Data Services has been deprecated and will no longer be available for download from the Microsoft Download Center.

WCF Data Services 仅支持早期版本的 Microsoft OData (V1-V3) 协议,且尚未处于积极开发阶段。WCF Data Services supported earlier versions of the Microsoft OData (V1-V3) protocol only and has not been under active development. Odata V1-V3 已被 OData V4 取代,这是由 OASIS 发布并经过 ISO 批准的行业标准。OData V1-V3 has been superseded by OData V4, which is an industry standard published by OASIS and ratified by ISO. OData V4 通过在 Microsoft. core提供的 odata v4 兼容核心库中得到支持。OData V4 is supported through the OData V4 compliant core libraries available at Microsoft.OData.Core. 支持文档可在 OData.Net上找到,并且 odata V4 服务库在 AspNetCore中可用。Support documentation is available at OData.Net, and the OData V4 service libraries are available at Microsoft.AspNetCore.OData.

RESTier 是 WCF Data Services 的后续版本。RESTier is the successor to WCF Data Services. RESTier 可帮助你在几分钟内启动标准化的、可查询的、基于 HTTP 的 REST 接口。RESTier helps you bootstrap a standardized, queryable, HTTP-based REST interface in minutes.

与 WCF Data Services 之前一样,Restier 提供了简单直接的方法来绘制查询并在其到达数据库之前和之后截获提交。Like WCF Data Services before it, Restier provides simple and straightforward ways to shape queries and intercept submissions before and after they hit the database. 与 Web API + OData 一样,你仍可以灵活地使用熟悉的方法添加自己的自定义查询和操作。And like Web API + OData, you still have the flexibility to add your own custom queries and actions with techniques you're already familiar with.

这是 WCF Data Services 快速入门的第二个任务。This is the second task of the WCF Data Services quickstart. 在此任务中,您将从 Visual Studio 中启动 WCF Data Services,还可以选择在 Web 浏览器中禁用源读取。In this task, you start the WCF Data Services from Visual Studio and optionally disable feed reading in the Web browser. 然后,通过 Web 浏览器向公开的资源提交 HTTP GET 请求,检索服务定义文档并访问数据服务资源。You then retrieve the service definition document as well as access data service resources by submitting HTTP GET requests through a Web browser to the exposed resources.

备注

默认情况下,Visual Studio 自动为计算机上的 localhost URI 分配一个端口号。By default, Visual Studio auto-assigns a port number to the localhost URI on your computer. 本任务在 URI 示例中使用端口号 12345。This task uses the port number 12345 in the URI examples. 有关如何在 Visual Studio 项目中设置特定端口号的详细信息,请参阅 创建数据服务。For more information about how to set a specific port number in your Visual Studio project see Creating the Data Service.

使用 Internet Explorer 请求默认服务文档To request the default service document by using Internet Explorer

在 Internet Explorer 的 " 工具 " 菜单中,选择 " Internet 选项",单击 " 内容 " 选项卡,单击 " 设置",然后清除 "启用源查看"。In Internet Explorer, from the Tools menu, select Internet Options, click the Content tab, click Settings, and clear Turn on feed viewing.

这可确保禁用源阅读。This makes sure that feed reading is disabled. 如果未禁用此功能,则 Web 浏览器会将返回的 AtomPub 编码文档视为 XML 源,而不是显示原始 XML 数据。If you do not disable this functionality, then the Web browser will treat the returned AtomPub encoded document as an XML feed instead of displaying the raw XML data.

备注

当浏览器无法将该源作为原始 XML 数据显示时,你应该仍能够以页面源代码的形式查看该源。If your browser cannot display the feed as raw XML data, you should still be able to view the feed as the source code for the page.

在 Visual Studio 中,按 F5 键开始调试应用程序。In Visual Studio, press the F5 key to start debugging the application.

在本地计算机上打开 Web 浏览器。Open a Web browser on the local computer. 在地址栏中,输入以下 URI:In the address bar, enter the following URI:

http://localhost:12345/northwind.svc

这会返回默认服务文档,其中包含由此数据服务公开的实体集的列表。This returns the default service document, which contains a list of entity sets that are exposed by this data service.

从 Web 浏览器访问实体集资源To access entity set resources from a Web browser

在 Web 浏览器的地址栏中,输入以下 URI:In the address bar of your Web browser, enter the following URI:

http://localhost:12345/northwind.svc/Customers

这会返回 Northwind 示例数据库中所有客户的集。This returns a set of all customers in the Northwind sample database.

在 Web 浏览器的地址栏中,输入以下 URI:In the address bar of your Web browser, enter the following URI:

http://localhost:12345/northwind.svc/Customers('ALFKI')

这会返回特定客户 ALFKI 的实体实例。This returns an entity instance for the specific customer, ALFKI.

在 Web 浏览器的地址栏中,输入以下 URI:In the address bar of your Web browser, enter the following URI:

http://localhost:12345/northwind.svc/Customers('ALFKI')/Orders

这会遍历客户与订单之间的关系,以返回特定客户 ALFKI 的所有订单的集。This traverses the relationship between customers and orders to return a set of all orders for the specific customer ALFKI.

在 Web 浏览器的地址栏中,输入以下 URI:In the address bar of your Web browser, enter the following URI:

http://localhost:12345/northwind.svc/Customers('ALFKI')/Orders?$filter=OrderID eq 10643

这会筛选属于特定客户 ALFKI 的订单,以便只根据提供的 OrderID 值返回特定订单。This filters orders that belong to the specific customer ALFKI so that only a specific order is returned based on the supplied OrderID value.

后续步骤Next Steps

已成功从 Web 浏览器访问 WCF Data Services,浏览器向指定资源发出 HTTP GET 请求。You have successfully accessed the WCF Data Services from a Web browser, with the browser issuing HTTP GET requests to specified resources. 使用 Web 浏览器,可以轻松试验请求的寻址语法并查看结果。A Web browser provides an easy way to experiment with the addressing syntax of requests and view the results. 不过,通常情况下并不会通过此方式访问生产数据服务。However, a production data service is not generally accessed by this method. 通常,应用程序会通过应用程序代码或脚本语言与数据服务进行交互。Typically, applications interact with the data service through application code or scripting languages. 接下来,您将创建一个客户端应用程序,该应用程序使用客户端库访问数据服务资源,就像它们是公共语言运行时 (CLR) 对象一样:Next, you will create a client application that uses client libraries to access data service resources as if they were common language runtime (CLR) objects:

另请参阅See also

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值