Take the 2-minute tour ×

A strange/silly question but.. I have created a simple WCF service that listens for requests for data from a database. It runs normally as a service on my machine no problem, but I was wondering - could this WCF service be used as a normal class? Say something like

public static void main (String [] args) {
    MyWcfService service = new MyWcfService ();
    /* Code to set-up and start listening for requests... */

Or would it simply have to run as a service on my machine?

share|improve this question
Have you tried it? –  John Koerner Jan 25 '13 at 23:41
add comment

2 Answers

Depends what do you want to achieve:

  • If use class's functionality, yes, you can just instantiate it and call it's members
  • If use it as a real WCF service, no, you need to host it first. In IIS or Windows Service, etc.
share|improve this answer
What I have is a server to parse downloaded data and send notifications to an Android device - I was hoping to create some sort of REST service so that the Android app could send requests to the server e.g. get data, changing parameters and so on –  SCassidy1986 Jan 26 '13 at 0:12
Now that I think about it... I don't really need it as a WCF service - even just a simple HttpListener that can accept REST requests would be brilliant, I just have very little to no experience of doing this and was hoping for a few pointers thats all! –  SCassidy1986 Jan 26 '13 at 0:18
@SCassidy1986 - sounds like Web API might be interesting to you: asp.net/web-api –  Tim Medora Jan 26 '13 at 1:50
add comment

Yes, you can self-host a WCF service in console application if that is what you want. You do not need IIS or a Windows service to host a WCF service. This is quite convenient for development and debugging, but probably not something you want for production. See this for a detailed example. I have modified the example to configure an endpoint completely in code below. Again, not something you want all the time.

public static void Main()
    MyWcfService instance = new MyWcfService();
    using (ServiceHost serviceHost = new ServiceHost(instance))
        var endpoint = serviceHost.AddServiceEndpoint(typeof(IMyWcfService), new NetTcpBinding(), "net.tcp://localhost:8000/MyWcfService");

        // The service can now be accessed.
        Console.WriteLine("The service is ready at {0}", endpoint.Address);

Note that this uses a single instance to service all calls where as typically WCF would create instances of the service class as needed.

share|improve this answer
add comment

Your Answer


