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

时间:2011-02-11 15:10:47

标签: 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网址时,我看到了这一点:

<?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);

3 个答案:

答案 0 :(得分:1)

您可以在已定义IQueryable&lt;&gt;的位置共享上下文定义吗?属性。我想到了两件事:首先,属性必须是IQueryable类型&lt;&gt;或某种衍生自它的类型。第二,由IQueryable&lt;&gt;引用的元素类型。必须是实体类型,即它们必须具有在其中声明的关键属性。

希望这有帮助。

由于 PRATIK

答案 1 :(得分:1)

服务操作(EDM中的功能导入)未在服务文档中公开。只有实体集在那里暴露。 如果您希望在服务文档中公开您的数据,请将实体设置出来。根据提供商型号,这有所不同。通常,它意味着在您的上下文类中公开IQueryable类型的属性。请注意,T必须是实体类型(必须有密钥)。

答案 2 :(得分:0)

或者您可以创建这样的扩展方法:

public static class TestEntitiesExtensions
{
    public static IEnumerable<Package> GetQueryablePackages(this TestEntities context)
    {
        var uri = new Uri(context.BaseUri, "GetQueryablePackages");
        return context.Execute<Package>(uri);
    }
}