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
4

3 回答 3

11

如果您要将服务映射到自定义路径,则该列表中缺少一个小步骤。 你可以在这里找到它

引用缺少的步骤:

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

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

"api"您正在使用的自定义路径的名称在哪里。

于 2012-11-24T14:26:38.073 回答
8

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

<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/

于 2012-05-14T18:43:22.290 回答
2

我遇到了这个确切的问题,但找不到直接的答案——在最简单的 ServiceStack 演示中出现 403.14 错误。

..:: 简单答案::..

你的答案很简单。您通过提供 3 而不是 Mythz 提到的 1 来混淆您的处理程序。此外,您的请求没有指定的路线。

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

这将解决您的 403.13 错误(语义问题),您可以转到 http://{localdomain}:{port}/hello 并实际查看元数据(用分配给 IIS Express 的实际端口号替换 {port}你)。如果不进行此调整,您将需要访问 http://{localdomain}:{port}/metadata。

..:: 详细解答 ::..

路由,因为它与 ServiceStack 中的 IIS 相关,是通过语义/约定完成的。由于这些路由是动态的,当 IIS 在运行时没有提供正确的路由时,它会假定存在文件夹问题(物理路径)并抛出 403.14 错误。同时,如果您提供了多个路径而应该只有一个路径,那么在运行时当一切都连接好时会发生不好的事情。

为了确保您拥有所有必需品,这里是您需要对提供的原始代码进行的所有调整。

一个。调整 Web 配置文件以仅处理 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>

湾。进行本文前面所述的路线调整。

于 2014-01-17T02:18:39.673 回答