我是第一次构建服务堆栈:hello world。
我已遵循here中的分步指南:
但它给了我一个错误:找不到请求的处理程序:可能缺少的部分是什么?感谢。
这是我的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
答案 0 :(得分:11)
如果要将服务映射到自定义路径,则该列表中缺少一小步。 You can find it here:
引用缺少的步骤:
您还需要在AppHost中配置根路径。
public override void Configure(Container container)
{
SetConfig(new EndpointHostConfig { ServiceStackHandlerFactoryPath = "api" });
}
其中"api"
是您正在使用的自定义路径的名称。
答案 1 :(得分:8)
您似乎正在尝试在 / 根路径以及/servicestack
和/api
个自定义路径的混合中托管ServiceStack。你需要选择其中一个,而不是所有的组合3.如果你想在/ root path主持,那么就是配置:
<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/
。
答案 2 :(得分:2)
我遇到了这个问题但找不到直接答案 - 在最简单的ServiceStack演示中出现403.14错误。
.. ::简单答案:: ..
你的回答很简单。你通过提供3而不是Mythz提到的一个来混淆你的处理程序。此外,您的请求没有指定的路由。
[Route("/hello")]
public class Hello { public string Name { get; set; } }
这将解决您的403.13错误(语义问题),您可以转到http:// {localdomain}:{port} / hello并实际查看元数据(用实际端口号IIS替换{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>
湾进行本文前面所述的路线调整。