0

我正在尝试从我不太了解的服务中获取数据。

所以我得到了它的网址,比如 http://ABC.com/ABC.svc

所以我想把元数据作为 http://ABC.com/ABC.svc/ $metadata

它给了我:

<EntityType Name="E1">
- <Key>
<PropertyRef Name="E1k1" /> 
</Key>
< Property Name="E2" Type="Edm.String" Nullable="true"
 m:FC_TargetPath="SyndicationTitle" ..>


<ComplexType Name="OptionV1">
<Property Name="Value" Type="Edm.Int32" Nullable="true" /> 

... and a lot more.

我如何找出 ABC.svc/ 旁边的内容???

我想编写查询来访问数据。有人可以指出我的下一步应该是什么吗?并且从元数据生成此查询的任何学习资源都将是 hlpful。

谢谢

4

2 回答 2

1

LinqPad provides a very simple means for getting started with OData services (assuming some familiarity with LINQ). If you will primarily be primarily consuming this application from .NET, I'd recommend starting with this application. You point it to the $metadata endpoint and it generates proxy classes which allow you to work with the OData service much like you would in a plain-old-.NET-app. On the Results Log tab, it will output the URL used to query the OData service, which you can then pick up and tweak in Fiddler. (For more about how to use OData + Fiddler, see this blog post.)

If you'll primarily be using the OData service from JavaScript, you might want to start by understanding the URI conventions better or by playing around with data.js.

于 2012-07-05T14:53:40.003 回答
1

There are two ways:

1) Using the service document. Navigate to the ABC.svc, that should return a service document, that is an ATOM Service payload which contains the names of the entity sets available from the service. For a sample of such you can go to http://services.odata.org/OData/OData.svc/. This should return a document with three collections (Entity sets). The href attribute is a relative URI to the entity set (relative to the xml:base which is usually the base of the service). So if for example your service has an entity set E1Set, then typically the address of it would be ABC.svc/E1Set.

2) Using the $metadata document and assuming the usual addressing scheme (note that this usually applies to the service but it doesn't have to). The $metadata document will define entity sets. Each of these is usually exposed by the service and typically follows the addressing scheme of ABC.svc/EntitySetName.

Once you navigate to the entity set, you should get back an ATOM feed with the entities in that set. The $metadata will help you recognize the shapes of the entities and the relationships.

Some services also have service operations or actions and so on. These are not exposed in the service document #1. Instead they are only visible in the $metadata as FunctionImport elements. They usually follow the addressing scheme of ABC.svc/FunctionImportName. But note that you might need to know something more about the service operation to be able to invoke it (what HTTP verb to use, what are the parameters, what it will do, and so on).

于 2012-07-05T10:14:10.703 回答