wcf - 为什么我的 WCF 数据服务方法没有出现在 OData 集合列表中?

标签 wcf security wcf-data-services

当我在浏览器中查看我的 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/

相关文章:

wcf - 读取 XML 数据时超出了最大字符串内容长度配额 (8192)

c# - WCF 数据服务,不要公开所有列

c# - WCF数据服务-从mysql查看超时过期问题

android - 最安全的移动数据库策略

wcf - 如何提高 WCF 数据服务性能

c# - 使用证书以编程方式实现 WCF

c# - Silverlight 和对 WCF 的同步调用

WCF net.tcp 唯一的服务给出TargetInitationException/ServiceModel.CommunicationException

c# - 使用参数化的 SqlCommand 是否可以使我的程序免受 SQL 注入(inject)的影响?

jquery - 在 jQuery 序列化之前加密表单发布数据