Visual Studio 2010 Automatic Attach To Process

后端 未结 10 2216
谎友^
谎友^ 2021-02-07 08:51

I am using visual studio 2010, my application has a multiu layer architect,

MainUI, WCFService, BLL and DAL

My MainUI communicated to WCF and WCF further commun

10条回答
  •  你的背包
    2021-02-07 09:34

    If this is for a self-hosted WCF windows service, you need to make your WCF service host configurable to either run in console or as a windows service. When you have run in console turned on, you can start debugging from visual studio.

    Create an app setting called "RunInConsole." In your service host startup method, have the following code:

    public class MyWindowsService : ServiceBase
    {
        public static void Main(string[] args)
        {
            // if configuration says to run in the console, run the service in a console app. otherwise, use windows
            // service to host application
            if (ConfigurationManager.AppSettings["RunInConsole"] == "true")
            {
                using (ServiceHost host = new ServiceHost(typeof(MyService)))
                {
                    host.Open();
                    Console.WriteLine("Press  to terminate the Host application.");
                    Console.ReadLine();
                }
            }
            else
                ServiceBase.Run(new MyWindowsService ());
        }
    
    }
    

    On all environments you deploy to, you'd always have this config setting set to false or else the service will fail to start, but when debugging locally you'd set it to true.

提交回复
热议问题