Search code examples
wcf

How to run a WCF project locally?


I am trying to debug a WCF project. So can someone tell me a simple way to run this WCF project locally?

I loaded it in Visual Studio and when I tell it to run it says "A project of Output Type Class Library cannot be started." or something like that.

From there I come here, because I've exhausted my knowledge of WCF. Any answers may need to be severely "dumbed down".


Solution

  • This error simply means you have not set any start up project for WCF project. Try to set service host project as start up project if there is any. If you dont have any of them try to make service host project locally and add a reference to that project in your service host project.

    A simple console hosting project will look like this

    using System.ServiceModel;
    namespace WcfDemoHost
    {
        class Program
        {
            static void Main(string[] args)
            {
                try
                {
    
                ServiceHost svchost = new ServiceHost(typeof(yourServiceClassNameHere));
                svchost.Open();
    
    
                Console.WriteLine("Service Started");
    
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
    

    }

    there are also several method for hosting WCF services locally like hosting in Windows service, IIS, Console, in windows form etc.You also need to add App.config file for configuring your service like service endpoint and many things. I am providing you some youtube tutorial link that will help you a lot in understanding WCF. I hope this tutorial will help you a lot.

    https://www.youtube.com/watch?v=QmfPmqMk9Xs&list=PL6n9fhu94yhVxEyaRMaMN_-qnDdNVGsL1

    Go from part 3 and for hosting follow tutorial 24-30.