请求处理程序未找到:

10

我第一次构建服务堆栈:hello world。

我按照这里的逐步指南进行了操作:

但是它给我一个错误:未找到请求的处理程序:有什么部分缺失吗?谢谢。

这是我的global.asax.cs文件。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using ServiceStack.ServiceHost;
using ServiceStack.WebHost.Endpoints;

namespace ServiceStack.SearchService
{
    public class Global : System.Web.HttpApplication
    {
        public class Hello { public string Name { get; set; } }
        public class HelloResponse { public string Result { get; set; } }
        public class HelloService : IService<Hello>
        {
            public object Execute(Hello request)
            {
                return new HelloResponse { Result = "Hello, " + request.Name };
            }
        }



        /// Web Service Singleton AppHost
        public class HelloAppHost : AppHostBase
        {
            //Tell Service Stack the name of your application and where to find your web services
            public HelloAppHost()
                : base("Hello Web Services", typeof(HelloService).Assembly) { }

            public override void Configure(Funq.Container container) { }
        }

        protected void Application_Start(object sender, EventArgs e)
        {
            //Initialize your application
            var appHost = new HelloAppHost();
            appHost.Init();
        }


        void Application_End(object sender, EventArgs e)
        {
            //  Code that runs on application shutdown

        }

        void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs

        }

        void Session_Start(object sender, EventArgs e)
        {
            // Code that runs when a new session is started

        }

        void Session_End(object sender, EventArgs e)
        {
            // Code that runs when a session ends. 
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer 
            // or SQLServer, the event is not raised.

        }

    }
}

这是我的web.config文件:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <connectionStrings>
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>
    <membership>
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <profile>
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
      </providers>
    </profile>
    <roleManager enabled="false">
      <providers>
        <clear />
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>
    <httpHandlers>
      <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
      <add path="api*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
    </httpHandlers>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
    </handlers>
  </system.webServer>
  <location path="servicestack">
    <system.web>
      <httpHandlers>
        <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
        <add path="servicestack*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
      </httpHandlers>
    </system.web>
    <!-- Required for IIS 7.0 -->
    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true" />
      <validation validateIntegratedModeConfiguration="false" />
      <handlers>
        <add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
      </handlers>
    </system.webServer>
  </location>
</configuration>

我通过在浏览器中输入 来浏览它。

http://localhost:50097/ServiceStack.SearchService/servicestack/metadata
3个回答

11

在该列表中还缺少一小步,如果要将服务映射到自定义路径,则需要此步骤。您可以在此处找到:

引用缺失的步骤:

您还需要在AppHost中配置根路径。

public override void Configure(Container container)
{
    SetConfig(new EndpointHostConfig { ServiceStackHandlerFactoryPath = "api" });
}

其中 "api" 是您使用的自定义路径的名称。


1
+1 这似乎在文档这里中缺失了 @mythz - D'Arcy Rittich

8

看起来你想在/根路径和/servicestack/api自定义路径的混合位置上托管ServiceStack。你需要选择其中一个,而不是所有三个的组合。如果你想在/根路径托管,请使用以下配置:

<system.web>
  <httpHandlers>
    <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
  </httpHandlers>
</system.web>

<!-- Required for IIS 7.0 -->
<system.webServer>
  <handlers>
    <add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
  </handlers>
</system.webServer>

以上应该替换每个其他的ServiceStack配置映射。完成此操作后,您应该能够在以下位置查看元数据页面:http://localhost:50097/metadata 注意:如果您正在端口上运行ASP.NET,则不太可能还具有虚拟目录路径/ServiceStack.SearchService/

你在使用 ServiceStack 做得非常好。我刚试了这里的 CustomAuthenticationMvc 项目 https://github.com/ServiceStack/ServiceStack.UseCases/tree/master/CustomAuthenticationMvc,它运行得很好! :) 继续保持出色的工作... 我计划从 MonoTouch iOS 应用程序中调用 Web 服务。 - Leniel Maccaferri
我的教程阅读暗示如果你使用了NuGet,你就不需要手动创建web.config条目。但我还是不得不这样做。另外:正如其他地方指出的那样,如果你从MVC应用程序开始,你必须注释掉默认路由 - 这最终为我解决了问题。 - GeorgeBarker

2

我曾经遇到过类似的问题,但却找不到一个明确的答案 - 在最简单的ServiceStack演示中出现了403.14错误。

..:: 简短的回答 ::..

你的答案很简单。 你提供了3个处理程序,而不是像Mythz提到的那样只提供一个。 此外,你没有为你的请求指定路由。

[Route("/hello")]
public class Hello { public string Name { get; set; } }

这将解决你的403.13错误(语义问题),并且你可以访问 http://{localdomain}:{port}/hello 并实际查看元数据(将{port}替换为IIS Express分配给你的实际端口号)。如果没有进行这个调整,你需要访问 http://{localdomain}:{port}/metadata。
在ServiceStack中,与IIS相关的路由是通过语义/约定完成的。由于这些路由是动态的,当IIS在运行时未提供正确的路由时,它会认为存在文件夹问题(物理路径),并抛出403.14错误。同时,如果你提供了多个路径,而应该只有一个路径,则在运行时连接所有内容时会发生不好的事情。
为确保你拥有所有必要的内容,以下是对原始代码所做的所有调整:
a. 调整web config文件以处理仅一个路径,如Mythz响应中所探讨的那样。
<system.web>
  <httpHandlers>
    <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
  </httpHandlers>
</system.web>

<!-- Required for IIS 7.0 -->
<system.webServer>
  <handlers>
    <add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
  </handlers>
</system.webServer>
要求: 对本帖中描述的路由调整进行操作。

b. 在本文中描述的方式对路由进行调整。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接