C# 客户端不需要通过网址提供对外接口

private static System.Threading.Mutex mutex;
        private const string title = "软件网络服务";
        private const string version = "1.2017.1117.1";     

        static void Main(string[] args)
        {
            mutex = new System.Threading.Mutex(true, title);
            if (mutex.WaitOne(0, false))
            {
                Console.Title = title;
                forbidden_CloseButton();
                //Assembly.Load("ZrTBMWebService.NET4.0, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
                var config = new HttpSelfHostConfiguration("http://localhost:9156");
                config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{action}/{id}", new { id = RouteParameter.Optional });

                using (var httpServer = new HttpSelfHostServer(config))
                {
                    httpServer.OpenAsync().Wait();
                    Console.WriteLine("");
                    Console.WriteLine(title);
                    Console.WriteLine("");
                    Console.WriteLine("webapi 服务({0})已启动, 按回车退出。", version);
                    Console.WriteLine("");
                    Console.WriteLine(System.DateTime.Now);
                    Console.ReadLine();
                }
                mutex.ReleaseMutex();
            }

            
        }

 

posted @ 2017-12-18 15:11  事理  阅读(219)  评论(0编辑  收藏  举报