1

モジュール式の ServiceStack 実装をセットアップしようとしていますが、プラグインの対処方法がわかりません。

これが私の 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}/heartbeat からのもので、メタは from localhost}/metadata にあります。

{from 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
4

1 に答える 1

1

このコードは、あなたが想定しているようなサービスに URL プレフィックスを与えません。

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

代わりに、optionalはその ServiceのDefaultRequestparams string[] atRestPathsルートのルートのみを指定します。属性を使用してデフォルトの操作を指定できます。例:[DeafultRequest]

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

これにより、リクエスト DTO ではなくインラインでルートを指定できます。つまり、次のようになります。

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

ただし、Request DTO で既にルートを取得しているため、ここではそれらを無視できます。つまり、次のようになります。

_appHost.RegisterService<StoreService>();

/storesただし、不足しているURL プレフィックスを含める必要があります。たとえば、次のようになります。

[Route("/stores/{State}/{City}/{Name*}")]
[Route("/stores/{Id}")]
public class Store : IReturn<StoreResponse> { .. }
于 2013-11-08T23:15:32.580 に答える