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

时间:2015-10-03 16:33:26

标签: c# asp.net nhibernate asp.net-web-api asp.net-boilerplate

我第一次使用ASP.NET样板文件。我已成功应用 ApplicationName.Core ApplicationName.Application ApplicationName.ORM (NHibernate)库。

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

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

Error 404.0 for WebApi

我需要一些建议,确切地说我弄错了。我的想法是我可能需要在应用程序的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>

感谢您的协助。

1 个答案:

答案 0 :(得分:1)

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