2012-05-14 47 views
8

Tôi đang xây dựng một chồng dịch vụ lần đầu tiên: hello world.Xử lý yêu cầu không tìm thấy:

Tôi đã theo các hướng dẫn từng bước trong here:

nhưng nó đem lại cho tôi một lỗi: Handler cho Yêu cầu không tìm thấy: những gì có thể là một phần thiếu? cảm ơn.

đây là global.asax.cs tôi

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. 

     } 

    } 
} 

đây là web.config của tôi:

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

tôi duyệt nó bằng cách gõ vào trình duyệt.

http://localhost:50097/ServiceStack.SearchService/servicestack/metadata 

Trả lời

7

Dường như bạn đang cố gắng để lưu trữ ServiceStack ở cả đường dẫn gốc / và tại một hỗn hợp của /servicestack/api đường dẫn tùy chỉnh. Bạn cần phải chọn một trong số họ, không phải là một sự kết hợp của tất cả 3. Dưới đây là cấu hình nếu bạn muốn lưu trữ tại / 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> 

Trên đây nên thay thế tất cả các bản đồ ServiceStack cấu hình khác. Một khi bạn đã làm điều này bạn sẽ có thể để xem các trang siêu dữ liệu tại địa chỉ:

http://localhost:50097/metadata

Lưu ý: Nếu bạn đang chạy ASP.NET trên một cổng không chắc rằng bạn cũng có đường dẫn thư mục ảo /ServiceStack.SearchService/.

+0

Bạn đang làm một công việc tuyệt vời với 'ServiceStack'. Chỉ cần thử dự án 'CustomAuthenticationMvc' từ đây https://github.com/ServiceStack/ServiceStack.UseCases/tree/master/CustomAuthenticationMvc và nó hoạt động rất tốt! :) Tiếp tục công việc TUYỆT VỜI ... Tôi dự định gọi dịch vụ web từ ứng dụng MonoTouch iOS. –

+0

thx - vui vì bạn đang thích nó :) – mythz

+0

Việc đọc hướng dẫn của tôi ngụ ý rằng nếu bạn sử dụng nuget, bạn sẽ không cần phải thực hiện các mục nhập web.config theo cách thủ công. Tôi phải. CSONG: Như đã chỉ ra ở nơi khác nếu bạn bắt đầu với một ứng dụng MVC bạn phải bình luận ra các tuyến đường mặc định - đó là những gì cuối cùng đã sửa nó cho tôi. – GeorgeBarker

11

Có một bước nhỏ bị thiếu trong danh sách mà bạn cần nếu bạn định ánh xạ dịch vụ tới đường dẫn tùy chỉnh. You can find it here:

Để trích dẫn bước mất tích:

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

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

đâu "api" là tên của con đường tùy chỉnh bạn đang sử dụng.

+1

+1 Điều này dường như bị thiếu trong tài liệu [ở đây] (http://servicestack.net/ServiceStack.Hello/) @mythz – RedFilter

+0

Điều này giải quyết được vấn đề của tôi. – saille

2

Tôi đã gặp phải vấn đề chính xác mà tôi gặp phải và không thể tìm thấy câu trả lời đúng - nhận được lỗi 403.14 trên bản demo ServiceStack đơn giản nhất.

.. :: Simple trả lời :: ..

câu trả lời của bạn là đơn giản. Bạn đã nhầm lẫn xử lý của bạn bằng cách cung cấp 3 thay vì một như đã đề cập bởi Mythz. Ngoài ra, bạn không có một tuyến đường cụ thể cho yêu cầu của bạn.

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

này sẽ giải quyết cả hai 403,13 lỗi (vấn đề ngữ nghĩa) của bạn và bạn có thể vào http của bạn: // {localdomain}: {port}/hello và thực sự thấy các siêu dữ liệu (thay thế {port} bằng số cổng thực tế IIS Express được gán cho bạn). Nếu không có điều chỉnh này, bạn cần truy cập http: // {localdomain}: {port}/metadata.

.. :: Câu trả lời chi tiết :: ..

Định tuyến, vì nó liên quan đến IIS trong ServiceStack được thực hiện theo ngữ nghĩa/quy ước. Vì các tuyến này là động, khi IIS không được cung cấp định tuyến thích hợp trong thời gian chạy, nó giả định rằng có một vấn đề thư mục (đường dẫn vật lý) và ném lỗi 403.14. Đồng thời, nếu bạn cung cấp nhiều hơn một con đường mà chỉ nên có một con đường, những điều xấu xảy ra vào thời gian chạy khi mọi thứ được kết nối.

Chỉ cần đảm bảo bạn có tất cả các yếu tố cần thiết, dưới đây là tất cả các điều chỉnh bạn cần thực hiện cho mã ban đầu được cung cấp.

a. Điều chỉnh tệp cấu hình web để xử lý chỉ một đường dẫn như được khám phá trong phản hồi 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. Thực hiện điều chỉnh tuyến đường được mô tả trước đó trong bài đăng này.

Các vấn đề liên quan