0
votes

I am writing my first WCF service. I have a few operations that are using Entity Framework - grabbing some data and returning JSON string.

I can invoke the operations successfully using the wcfClient, but when I try to invoke the operation in my own test console app I get the following error in the entity model constructor :

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid. Code in DataContract class:

[DataContract]
public class DrawSystemService : IDrawSystemService
{
    public string GetDrawEntry(string entryId)
    {
        using (MyEntities context = new MyEntities())
        {
            tblDrawEntry drawEntry = null;
            try
            {
                drawEntry = context.tblDrawEntries.FirstOrDefault(e => e.DrawEntryID == new Guid(entryId));
            }
            catch (Exception ex)
            {
            }
            string json = JsonConvert.SerializeObject(drawEntry, Formatting.Indented);
            return json;
        }
    }
}

Code in console app:

            WcfDrawSystemLibrary.DrawSystemService drawSystem = new DrawSystemService();

        drawSystem.GetDrawEntry("665B534B-73EE-4385-A9BA-02A25CB5FE4D");
1
care to narrow that down - i.e. be more specific - tom

1 Answers

1
votes

In general the problem could be that you for got to add a proper connection string to your app.config of your console application. Take a copy of the connection string from your service configuration and add it to your app.config of your console.

On the other hand I notice that your service is marked as [DataContract] while is should be [ServiceContract]. Maybe this is typo and you already did that on your interface level

In case you really treat this service as DataContract then I would suggest to review this as it is not how it should be.