2012-05-14 4 views
8

저는 처음으로 서비스 스택을 작성합니다. 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 

답변

7

당신이 / 루트 경로에서와 /servicestack/api 사용자 정의 경로의 혼합물에 ServiceStack 모두를 호스트하려는 것 같습니다. 당신은 당신이 / root path에서 개최하려는 경우 여기에 설정입니다 그들 중 하나, 모두 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/.

+0

당신은'ServiceStack'으로 훌륭한 일을하고 있습니다. 'CustomAuthenticationMvc' 프로젝트는 https://github.com/ServiceStack/ServiceStack.UseCases/tree/master/CustomAuthenticationMvc에서 시험해 보았습니다. :) 굉장한 작품을 계속 ... MonoTouch iOS 응용 프로그램에서 webservice를 호출 할 계획입니다. –

+0

thx - 당신이 그것을 즐기고있어 기쁩니다 :) – mythz

+0

튜토리얼을 읽었을 때, 당신이 nuget을 사용했다면 수동으로 web.config 항목을 만들 필요가 없다는 것을 암시했습니다. 나는해야했다. 또한 : MVC 응용 프로그램으로 시작한 경우 다른 곳에서 지적한대로 기본 경로를 주석 처리해야합니다. 이것이 마침내 해결되었습니다. – GeorgeBarker

11

사용자 지정 경로에 서비스를 매핑하는 데 필요한 해당 목록에서 누락 된 작은 단계가 있습니다. You can find it here :

누락 된 단계를 인용하려면 :

"api" 사용중인 사용자 지정 경로의 이름입니다

You also need to configure the root path in your AppHost.

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

.

+1

+1이 문서에서 [http://servicestack.net/ServiceStack.Hello/] @mythz – RedFilter

+0

이 누락 된 것 같습니다 내 문제가 해결되었습니다. – saille

2

가장 정확한 ServiceStack 데모에서 403.14 오류가 발생하여 정확한 답변을 찾을 수 없었습니다.

.. :: 간단한 대답 :: ..

당신의 대답은 간단하다. Mythz에서 언급 한 것 대신 3 개를 제공하여 핸들러를 혼란스럽게 만들었습니다. 또한 요청한 경로가 지정되지 않았습니다.

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

이 모두 당신의 403.13 오류 (의미 론적 문제) 해결하고 당신이 당신의 HTTP에 갈 수 : // {LOCALDOMAIN} {포트}/안녕하세요 실제로와 메타 데이터 (은 {포트} 대체를 참조 IIS Express가 귀하에게 할당 한 실제 포트 번호). 이 조정을하지 않으면 http : // {localdomain} : {port}/metadata로 이동해야합니다.

.. :: 세부 답변 :: ..

라우팅은 ServiceStack에서 IIS와 관련되어 있으므로 의미/규칙에 따라 수행됩니다. 이러한 경로는 동적이므로 IIS가 런타임에 적절한 라우팅을 제공하지 않으면 폴더 문제 (실제 경로)가 있다고 가정하고 403.14 오류가 발생합니다. 동시에 하나만 존재해야하는 경로를 두 개 이상 제공하면 모든 것이 유선이되어 런타임에 나쁜 일이 발생합니다.

모든 필수 요소가 있는지 확인하기 위해 제공된 원래 코드를 수정해야합니다.

a. 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의 탐구로 한 경로를 처리하기 위해 웹 설정 파일을 조정합니다. 이 게시물 앞부분에 설명 된 경로 조정을하십시오.

관련 문제