IReturn インターフェイスを備えた「新しい」API を使用しています。私のすべての呼び出しは、プラグイン登録で指定されたものではなく、/api/json/syncreply ルートに解決されています。
ブラウザで URL にアクセスすると正しい応答が得られるため、その部分は機能していますが、JsonServiceClient を使用するとルートが正しく解決されません。
var dataService = new JsonServiceClient(baseUri);
dataService.Get(new BaseProductBenefitTypeEdit() { Code = ((BaseProductBenefitTypeInfo)obj).Code }
, onSuccess, onError);
Dtos
public class BaseProductBenefitTypeEdit : IReturn<BaseProductBenefitTypeEditResponse>
{
public string Code { get; set; }
}
public class BaseProductBenefitTypeEditResponse : IHasResponseStatus
{
public BaseProductBenefitTypeEditInfo BenefitType { get; set; }
public List<KeyValuePair> AvailableMostCommon { get; set; }
public List<KeyValuePair> AvailableTypes { get; set; }
public ResponseStatus ResponseStatus { get; set; }
}
私はプラグインを持っています
public class MaintenanceModule : IPlugin
{
public void Register(IAppHost appHost)
{
//baseProductBenefitTypes
appHost.Routes.Add<BaseProductBenefitTypeList>("/baseProductBenefitTypes", "GET");
appHost.Routes.Add<BaseProductBenefitTypeEdit>("/baseProductBenefitTypes/{code}/editForm", "GET");
appHost.Routes.Add<BaseProductBenefitTypeCreate>("/baseProductBenefitTypes/createForm", "GET");
appHost.Routes.Add<BaseProductBenefitTypeSave>("/baseProductBenefitTypes/{code}", "PUT");
appHost.Routes.Add<ChangeBaseProductBenefitTypesDisplayOrder>("/baseProductBenefitTypes/displayOrders", "POST");
appHost.RegisterService<BaseProductBenefitTypeService>();
Application_Start i 呼び出しでアプリケーションの開始時に Global.asax に
ServiceStackInitilizer.Run();
このように見える
public static class ServiceStackInitilizer
{
public static void Run()
{
var type = typeof(ServiceStack.ServiceInterface.Service);
var types = AppDomain.CurrentDomain.GetAssemblies()
.Where(x=>x.GetName().Name.StartsWith("MyApplication"))
.SelectMany(a => a.GetTypes())
.Where(type.IsAssignableFrom);
var assemblies = types.GroupBy(t => t.Assembly).Select(g => g.Key).ToArray();
new WebServiceAppHost("WebServiceAppHost", assemblies).Init();
}
}
WebServiceAppHost Configure メソッドで、プラグインを登録します。
public override void Configure(Funq.Container container)
{
JsConfig.IncludeNullValues = true;
SetConfig(new EndpointHostConfig
{
ServiceStackHandlerFactoryPath = "api",
DefaultContentType = ServiceStack.Common.Web.ContentType.Json,
DefaultJsonpCacheExpiration = new TimeSpan(0, 0, 0, 0),
GlobalResponseHeaders = { { "Cache-Control", "no-cache" } },
});
container.Adapter = new StructureMapContainerAdapter();
RegisterMyPlugins();
}
private void RegisterMyPlugins()
{
var type = typeof(IPlugin);
var plugins = AppDomain.CurrentDomain.GetAssemblies()
.Where(x => x.GetName().Name.StartsWith("Application"))
.SelectMany(a => a.GetTypes())
.Where(type.IsAssignableFrom);
foreach (var plugin in plugins)
{
Plugins.Add((IPlugin)plugin.CreateInstance());
}
}