gpt4 book ai didi

ServiceStack:为什么我的调用没有解析为正确的路由?

转载 作者:行者123 更新时间:2023-12-02 03:46:56 25 4
gpt4 key购买 nike

我正在使用带有 IReturn 接口(interface)的"new"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 中应用程序开始时的 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());
}
}

最佳答案

I am using a "new" api with IReturn interface. All my calls are being resolved to /api/json/syncreply route, rather then the ones specified in the plugin registration.

If I hit the url in browser I get correct reply, so that part is working, yet if use JsonServiceClient it does not resolve the route correctly.

请记住,服务客户端在调用您的服务时唯一可以访问的工件和元数据是 DTO。因此,您需要使用 [Route] 属性,以便客户端能够使用任何自定义的用户定义路由。

关于ServiceStack:为什么我的调用没有解析为正确的路由?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16406088/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com