当我在浏览器中查看我的 WCF 数据服务服务 (http://localhost/MyService.svc/) 的根时,我看到了这个:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<service xml:base="http://localhost/MyService.svc/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns="http://www.w3.org/2007/app">
<workspace>
<atom:title>Default</atom:title>
</workspace>
</service>
我希望看到一个集合列表。
当我转到 $metadata
URL 时,我看到了这个:
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="1.0">
<Schema Namespace="MyApp" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://schemas.microsoft.com/ado/2007/05/edm">
<ComplexType Name="Package">
<Property Name="Id" Type="Edm.String" Nullable="true" />
</ComplexType>
</Schema>
<Schema Namespace="MyApp" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://schemas.microsoft.com/ado/2007/05/edm">
<EntityContainer Name="PackageService" m:IsDefaultEntityContainer="true">
<FunctionImport Name="GetQueryablePackages" ReturnType="Collection(MyApp.Package)" m:HttpMethod="GET" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
为什么我的 GetQueryablePackages
集合没有出现?
我正在使用这些访问设置:
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
最佳答案
服务操作(EDM 中的函数导入)未在服务文档中公开。只有实体集在那里公开。 如果您希望在服务文档中公开您的数据,请从中创建一个实体集。这取决于提供者模型。通常这意味着在您的上下文类上公开 IQueryable 类型的属性。请注意,T 必须是实体类型(必须有键)。
关于wcf - 为什么我的 WCF 数据服务方法没有出现在 OData 集合列表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4970612/