Why doesn't my WCF services method appear in the OData collection list?

When I look at the root of my WCF Data Services service (http: //localhost/MyService.svc/) in a browser, I see this:

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

I would expect to see a list of collections.

When I go to the URL $metadata, I see this:

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

Why GetQueryablePackageswon't my collection appear?

I use these access options:

config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
+3
source share
3 answers

( EDM) . . , , . . , IQueryable . , T ( ).

+1

, IQueryable < > . , : IQueryable < > - , . -, , IQueryable < > , , .. , .

, .

Pratik

+1

Or you can create an extension method as follows:

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

Source: https://habr.com/ru/post/1791519/


All Articles