AllenG
AllenG

Reputation: 8190

Using WCF Service Class (.cs file) not as WCF

Okay, I'm not sure if there's a duplicate, because I can't think of a better way to ask this question.

I have a WCF Service (the Interface as the contract, and then a class which implements the Interface- as per usual). It's hosted, and everyone can see the service, and I can call the functions normally.

We're using Visual Studio 2005 (C#, in this case).

I'm trying to create a console application which references (not as a web reference) the WCF class, and call the methods. This is so I can debug it directly. I know this is possible (that is: I'm virtually certain it's possible) but every time I try, my console app blows up because I haven't fed it the WCF necessities (Endpoint, etc.). To which I'm inclined to shout, "Well, duh: I'm trying to call it as though it's a .dll, not a Web Service!" but I don't think that would help much.

The specific error I'm getting is "Could not find default endpoint element that references contract 'SafetyKleen.BizTalk.CryptoService.IRetrievalService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element." But, again, I'm specifically trying to avoid calling this through WCF.

Any suggestions would be appreciated.

Upvotes: 1

Views: 667

Answers (3)

davidpricedev
davidpricedev

Reputation: 2237

The error may be from the app.config file and/or service reference. If you are trying to use the same client project as the one that consumed the WCF service, you probably have a service reference and a bunch of WCF configuration in the app.config - or maybe you cleaned up the app.config but didn't remove the service reference?

Upvotes: 0

Ivan Gerken
Ivan Gerken

Reputation: 914

I did unit tests for WCF service classes instantiating them as plain classes. However, I suspect that things like OperationContext.Current might cause problems in such case.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039428

There should be nothing preventing you from creating a console application, referencing the assembly containing the service contract (interface) and the implementation, instantiating the implementation and directly invoking some method:

class Program
{
    static void Main()
    {
        var service = new MyService1();
        var result = service.SomeMethod(new SomeDataContract
        {
            Prop1 = "value 1"
        });
    }
}

No WCF involved in the call.

But for debugging purposes only you could also use the WcfTestClient utility.

Upvotes: 3

Related Questions