Search code examples
c#wcf-data-services.net-4.5

Not using a reference to a WCF data service


To avoid maintenance overhead using WCF Data Services I am avoiding generating service references.

Currently I use the System.Data.Services.Client.DataServiceContext class in combination with DataServiceQuery. This works but means there has to be some hard coded strings either in code or config - the entity set name and the URI.

What are the alternatives to this? Any pitfalls I need to be aware of?

I saw something that mentioned creating a ChannelFactory

However, this looked quite cumbersome or at least on the surface it didn't seem any better to what I am currently doing.

EDIT A bit more detail - here is the service to expose an EF DBContext:

public class DocumentService : DataService<DocumentContext>
{
    public static void InitializeService(DataServiceConfiguration config)
    {
        config.SetEntitySetAccessRule("Documents", EntitySetRights.All);
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
        config.UseVerboseErrors = true;
    }

    protected override DocumentContext CreateDataSource()
    {
        return new DocumentContext("DocumentsContext");
    }
}

And how I invoke it without an explicit reference:

new DataServiceContext(uri, maxVersion).CreateQuery<DocumentEntity>(entitySetName)....etc

What are the alternatives to this? = alternatives to the DataServiceContext class


Solution

  • I could have used:

    ObjectQuery - this can be manually constructed with some Entity Framework SQL and ObjectContext,which requires a connection string and supports LINQ to entities etc

    System.Data.EntityClient - this namespace also includes some classes for interacting directly with EF. These include the EntityDataReader class which returns streamed data as rows and columns - a subclass of DBDataReader

    As both methods bypass a service by requiring a direct connection to a database they were of limited utility. I have not tried using them.