2013-11-08 3 views
1

Я пытаюсь установить модульную реализацию ServiceStack, но я не могу понять, как обращаться к моему подключаемому модулю.Service Stack Plug-in Not Addressable

Вот мой ASP.Net MVC 4 Global.asax.cs:

public class MvcApplication : System.Web.HttpApplication 
{ 
    [Route("/heartbeat")] 
    public class HeartBeat 
    { 
    } 

    public class HeartBeatResponse 
    { 
     public bool IsAlive { get; set; } 
    } 

    public class ApiService : Service 
    { 
     public object Any(HeartBeat request) 
     { 
      var settings = new AppSettings(); 

      return new HeartBeatResponse { IsAlive = true }; 
     } 
    } 
    public class AppHost : AppHostBase 
    { 
     public AppHost() : base("Api Services", typeof(ApiService).Assembly) { } 

     public override void Configure(Funq.Container container) 
     { 
      Plugins.Add(new ValidationFeature()); 
      Plugins.Add(new StoreServices()); 
     } 
    } 
    protected void Application_Start() 
    { 
     new AppHost().Init(); 
    } 

Это загружает нормально, и я в состоянии видеть доступную службу "Heartbeat". Однако служба, загруженная подключаемым модулем, не найдена.

Вот плагин код:

public class StoreServices: IPlugin 
{ 
    private IAppHost _appHost; 

    public void Register(IAppHost appHost) 
    { 
     if(null==appHost) 
      throw new ArgumentNullException("appHost"); 

     _appHost = appHost; 
     _appHost.RegisterService<StoreService>("/stores"); 
    } 
} 

и соответствующий сервис, который загружает:

public class StoreService:Service 
{ 
    public Messages.StoreResponse Get(Messages.Store request) 
    { 
     var store = new Messages.Store {Name = "My Store", City = "Somewhere In", State = "NY"}; 
     return new Messages.StoreResponse {Store = store}; 
    } 
} 


[Route("/{State}/{City}/{Name*}")] 
[Route("/{id}")] 
public class Store : IReturn<StoreResponse> 
{ 
    public int Id { get; set; } 
    public string Name { get; set; } 
    public string City { get; set; } 
    public string State { get; set; } 
} 

public class StoreResponse 
{ 
    public Store Store { get; set; } 
} 

URL-адрес для запуска сердцебиения с локального хоста}/сердцебиения и мета может быть найденный с localhost}/metadata.

Когда я пытаюсь вызвать {из localhost}/stores/1234, хотя я получаю неразрешенный маршрут ?, но если вы видите атрибут маршрута в вызове службы, он должен решить?

Ниже ответ я получаю для магазинов просить:

Handler for Request not found: 


Request.ApplicationPath:/
Request.CurrentExecutionFilePath: /stores/123 
Request.FilePath: /stores/123 
Request.HttpMethod: GET 
Request.MapPath('~'): C:\Source Code\White Rabbit\SpiritShop\SpiritShop.Api\ 
Request.Path: /stores/123 
Request.PathInfo: 
Request.ResolvedPathInfo: /stores/123 
Request.PhysicalPath: C:\Source Code\White Rabbit\SpiritShop\SpiritShop.Api\stores\123 
Request.PhysicalApplicationPath: C:\Source Code\White Rabbit\SpiritShop\SpiritShop.Api\ 
Request.QueryString: 
Request.RawUrl: /stores/123 
Request.Url.AbsoluteUri: http://localhost:55810/stores/123 
Request.Url.AbsolutePath: /stores/123 
Request.Url.Fragment: 
Request.Url.Host: localhost 
Request.Url.LocalPath: /stores/123 
Request.Url.Port: 55810 
Request.Url.Query: 
Request.Url.Scheme: http 
Request.Url.Segments: System.String[] 
App.IsIntegratedPipeline: True 
App.WebHostPhysicalPath: C:\Source Code\White Rabbit\SpiritShop\SpiritShop.Api 
App.WebHostRootFileNames: [global.asax,global.asax.cs,packages.config,spiritshop.api.csproj,spiritshop.api.csproj.user,spiritshop.api.csproj.vspscc,web.config,web.debug.config,web.release.config,api,app_data,bin,obj,properties] 
App.DefaultHandler: metadata 
App.DebugLastHandlerArgs: GET|/stores/123|C:\Source Code\White Rabbit\SpiritShop\SpiritShop.Api\stores\123 

ответ

1

Этот код не не дает вашим услугам URL префикс, как Вы предполагаете:

_appHost.RegisterService<StoreService>("/stores"); 

Вместо опционный params string[] atRestPaths определяет только маршруты для маршрута DefaultRequest. Можно указать, какая операция по умолчанию с помощью атрибута [DeafultRequest], например:

[DefaultRequest(typeof(Store))] 
public class StoreService : Service { ... } 

Что позволяет определить маршруты в линию, а не по требованию DTO, то есть:

_appHost.RegisterService<StoreService>(
    "/stores/{State}/{City}/{Name*}", 
    "/stores/{Id}"); 

Но вы уже получили маршруты на DTO запроса вы можете игнорировать их здесь, а именно:

_appHost.RegisterService<StoreService>(); 

Но вам необходимо включить отсутствующие /stores префикс URL, например:

[Route("/stores/{State}/{City}/{Name*}")] 
[Route("/stores/{Id}")] 
public class Store : IReturn<StoreResponse> { .. } 
Смежные вопросы