Owin自宿主WebApi和Odata服务


控制台程序采用自宿主方式提供您webApi服务和Odata服务。本例子采用两种方式做实现,一个是console控制程序自身采用Owin方式将Odata服务自宿主在自身。另一种方式是Console控制体程序采用Owin方式加载webApi网站dll方式。同时控制台程序实现了windows服务的注册和删除功能。
资源截图
代码片段和文件信息
using System;
using System.Linq;
using System.ServiceProcess;
using DebuggableOwinService1.framework;

namespace DebuggableOwinService1
{
    static class Program
    {
        // The main entry point for the windows service application.
        static void Main(string[] args)
        {
            try
            {
                // If install was a command line flag then run the installer at runtime.
                if (args.Contains(“-install“ StringComparer.InvariantCultureIgnoreCase))
                {
                    WindowsServiceInstaller.RuntimeInstall();
                }

                // If uninstall was a command line flag run uninstaller at runtime.
                else if (args.Contains(“-uninstall“ StringComparer.InvariantCultureIgnoreCase))
                {
                    WindowsServiceInstaller.RuntimeUnInstall();
                }

                // Otherwise fire up the service as either console or windows service based on UserInteractive property.
                else
                {
                    var implementation = new ServiceImplementation();

                    // If started from console file explorer etc run as console app.
                    if (Environment.UserInteractive)
                    {
                        ConsoleHarness.Run(args implementation);
                    }

                    // Otherwise run as a windows service
                    else
                    {
                        Servicebase.Run(new WindowsServiceHarness(implementation));
                    }
                }
            }

            catch (Exception ex)
            {
                ConsoleHarness.WriteToConsole(ConsoleColor.Red “An exception occurred in Main(): {0}“ ex);
            }
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2140  2018-04-03 09:57  DebuggableOwinService1App.config

     文件      66224  2013-08-16 10:43  DebuggableOwinService1inDebugdeMicrosoft.Data.Edm.resources.dll

     文件     282800  2013-08-16 10:55  DebuggableOwinService1inDebugdeMicrosoft.Data.OData.resources.dll

     文件      17584  2013-08-16 10:57  DebuggableOwinService1inDebugdeSystem.Spatial.resources.dll

     文件      25088  2018-04-03 10:48  DebuggableOwinService1inDebugDebuggableOwinService1.exe

     文件       2140  2018-04-03 09:57  DebuggableOwinService1inDebugDebuggableOwinService1.exe.config

     文件      58880  2018-04-03 10:48  DebuggableOwinService1inDebugDebuggableOwinService1.pdb

     文件      65712  2013-08-16 10:43  DebuggableOwinService1inDebugesMicrosoft.Data.Edm.resources.dll

     文件     278192  2013-08-16 10:55  DebuggableOwinService1inDebugesMicrosoft.Data.OData.resources.dll

     文件      17584  2013-08-16 10:57  DebuggableOwinService1inDebugesSystem.Spatial.resources.dll

     文件      67248  2013-08-16 10:43  DebuggableOwinService1inDebugfrMicrosoft.Data.Edm.resources.dll

     文件     292016  2013-08-16 10:55  DebuggableOwinService1inDebugfrMicrosoft.Data.OData.resources.dll

     文件      18096  2013-08-16 10:57  DebuggableOwinService1inDebugfrSystem.Spatial.resources.dll

     文件      65712  2013-08-16 10:43  DebuggableOwinService1inDebugitMicrosoft.Data.Edm.resources.dll

     文件     276656  2013-08-16 10:55  DebuggableOwinService1inDebugitMicrosoft.Data.OData.resources.dll

     文件      17584  2013-08-16 10:57  DebuggableOwinService1inDebugitSystem.Spatial.resources.dll

     文件      71856  2013-08-16 10:43  DebuggableOwinService1inDebugjaMicrosoft.Data.Edm.resources.dll

     文件     315056  2013-08-16 10:55  DebuggableOwinService1inDebugjaMicrosoft.Data.OData.resources.dll

     文件      18608  2013-08-16 10:57  DebuggableOwinService1inDebugjaSystem.Spatial.resources.dll

     文件      66736  2013-08-16 10:43  DebuggableOwinService1inDebugkoMicrosoft.Data.Edm.resources.dll

     文件     282288  2013-08-16 10:55  DebuggableOwinService1inDebugkoMicrosoft.Data.OData.resources.dll

     文件      18096  2013-08-16 10:57  DebuggableOwinService1inDebugkoSystem.Spatial.resources.dll

     文件     659120  2013-08-16 10:43  DebuggableOwinService1inDebugMicrosoft.Data.Edm.dll

     文件     654503  2013-08-16 10:43  DebuggableOwinService1inDebugMicrosoft.Data.Edm.xml

     文件    1518256  2013-08-16 10:55  DebuggableOwinService1inDebugMicrosoft.Data.OData.dll

     文件    3702833  2013-08-16 10:55  DebuggableOwinService1inDebugMicrosoft.Data.OData.xml

     文件     101032  2015-02-13 13:16  DebuggableOwinService1inDebugMicrosoft.Owin.dll

     文件      88232  2015-02-13 13:16  DebuggableOwinService1inDebugMicrosoft.Owin.Host.HttpListener.dll

     文件       8129  2015-02-13 13:16  DebuggableOwinService1inDebugMicrosoft.Owin.Host.HttpListener.xml

     文件      64680  2015-02-13 13:16  DebuggableOwinService1inDebugMicrosoft.Owin.Hosting.dll

............此处省略379个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)