0

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

Jaycee
  • 3,098
  • 22
  • 31
  • `This works but means there has to be some hard coded strings` if the strings can be changed by the user, you can just save them in a config file. In any case, you will need those endpoints to create a service reference. – Arian Motamedi Sep 10 '13 at 16:32

2 Answers2

1

The endpoints, contracts (interfaces + return types) and bindings are always needed in WCF, in fact service reference is generating them for you.

You can create a WCF Service invoker using ChannelFactories, however there will stil be the need to share the information mentioned before between the server and client.

There's a super good post in stackoverflow about how to create an WCF invoker using ChannelFactory.

I suggest Darin Dimitrov answer.

Community
  • 1
  • 1
margabit
  • 2,924
  • 18
  • 24
  • Thanks for the info, but I don't have a contract explicitly and am not sure the link is strictly applicable. See my edit on the question. – Jaycee Sep 11 '13 at 08:46
  • I seee. You are using ODATA with EF and WCF. The URI will always be needed and I guess the entity set name too. There's no way the client can magically figure out where the server is, or fetch some entities without specifiying at least the name – margabit Sep 11 '13 at 12:00
  • I think my question was badly worded. Yes they will always need that information but the main part of the question is really: what are the alternatives to using the DataServiceContext class if any? – Jaycee Sep 11 '13 at 12:26
0

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.

Jaycee
  • 3,098
  • 22
  • 31