如何将 ASP.NET 样板 WebApi class 库部署为独立的 Web 服务?

How do I deploy ASP.NET boilerplate WebApi class library as a stand-alone web service?

我是第一次使用 ASP.NET 样板。我已经能够应用 ApplicationName.CoreApplicationName.ApplicationApplicationName.ORM (NHibernate) 库成功。

但是,我需要将我的应用程序服务作为 Web 服务提供。我的理解是,一旦我将名为 ApplicationName.WebApi 的库作为 Web 应用程序部署到 IIS,我就会自动拥有一个通过 /api/services 公开我的应用程序服务的 Web 服务/.

当我这样做时,当我尝试通过浏览器向 API 发出请求时,我不断收到错误 404.0,如下所示:

我需要一些关于我到底在哪里出错的建议。我的想法是,我可能必须向应用程序的 web.config 添加一些额外的配置。

当前配置如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>  
  <connectionStrings>
    <add name="Default" connectionString="***" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http.WebHost" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.0.34.0" newVersion="1.0.34.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.3.0.0" newVersion="3.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="AutoMapper" publicKeyToken="be96cd2c38ef1005" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.4.0" newVersion="4.0.4.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.webServer> <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
        <handlers>
            <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
            <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
  </system.webServer>
</configuration>

感谢您的协助。

您需要部署 ApplicationName.Web。 ApplicationName.WebApi 是一个 class 库。