Open Closed

Having problems with complex API parameters using AbpHttpClientProxyingOptions #2314


User avatar
0
mc86 created

Hi guys

I created an api like

   [HttpGet]
        [Route("dx/[action]")]
      
        public virtual Task<LoadResult> GetDxListAsync(DataSourceLoadOptionsBase input)//[FromBody]
        {
            return _mailsAppService.GetDxListAsync(input);
        }

There is a complex parameter(DataSourceLoadOptionsBase ) in my API. and generate a static client. but"Volo.Abp.Http.Client.ClientProxying" didn't handle it well.

then i found that in v5.0. there is a way to handle it myself. github so I add those code in my service's Httpapi.client

//in OaServiceHttpApiClientModule
 Configure<AbpHttpClientProxyingOptions>(options =>
            {
                options.QueryStringConverts.Add(typeof(DataSourceLoadOptionsBase), typeof(DataSourceLoadOptionsBaseToQueryString));
            });

            //static
            context.Services.AddStaticHttpClientProxies(
             typeof(OaServiceApplicationContractsModule).Assembly
            );
            
//DataSourceLoadOptionsBaseToQueryString.cs
public class DataSourceLoadOptionsBaseToQueryString : IObjectToQueryString<DataSourceLoadOptionsBase>, ITransientDependency
    {
        public Task<string> ConvertAsync(DataSourceLoadOptionsBase values)
        {
            if (values==null)
            {
                return null;
            }

          
            return Task.FromResult("12345678");
        }
    }

but after i called the method "GetDxListAsync" in my blazor client nothing happened.

is there someone can help me?


20 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Is your project tiered?

    DataSourceLoadOptionsBaseToQueryString : IObjectToQueryString<DataSourceLoadOptionsBase >

  • User Avatar
    0
    mc86 created

    Hi maiiming My project is a Microservice Solution

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Try to configure it in your blazor project?

    Configure(options =>
    {
        options.QueryStringConverts.Add(typeof(DataSourceLoadOptionsBase), typeof(DataSourceLoadOptionsBaseToQueryString));
    });
    
  • User Avatar
    0
    mc86 created

    In main blazor or in my service blazor?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Please share your project structure.

  • User Avatar
    0
    mc86 created

    main folder

    services apps

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I think you should add it in your apps projects.

  • User Avatar
    0
    mc86 created

    got it after I try it, I will send feedback.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    OK : )

  • User Avatar
    0
    mc86 created

    HI maliming

    it doesn't work.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you try to reproduce this in a brand new **Microservice **project? liming.ma@volosoft.com

  • User Avatar
    0
    mc86 created

    My Microservice project is created in v5.0 rc and I just updated it to v5.0 and just add one entity to it。

    I will creat Microservice project to test it.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    public virtual Task GetDxListAsync(DataSourceLoadOptionsBase input)//[FromBody]

    Is this bind from the querystring?

  • User Avatar
    0
    mc86 created

    Yes.

    problem is that the method doesn't work. I can get data from my api but if this method is working then the blazor client should request a URL like HTTP://remotehost/action?123445678.

    public class DataSourceLoadOptionsBaseToQueryString : IObjectToQueryString, ITransientDependency
        {
            public Task ConvertAsync(DataSourceLoadOptionsBase values)
            {
                if (values==null)
                {
                    return null;
                }
    
              
                return Task.FromResult("12345678");
            }
        }
    

    i set a Breakpoint in the method but it was not hitted

    ///////////////////////////////////////////////////////////////////// //url should like this at the end. ?requireTotalCount=true&take=10&totalSummary=[{"Selector":"SendTime","SummaryType":"count"}]

    but //now the httpclient get the wrong url. ?requireTotalCount=true&take=10&totalSummary=Devextrem.asp.net.summaryinfo

    so I want to use QueryStringConverts to fix that.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    https://zoom.us/j/97027636243?pwd=ZHNySmlocFl5enJUNVBzTnZqaGdVZz09

  • User Avatar
    0
    mc86 created

    hi maliming 增加转换器后

    Configure<AbpHttpClientProxyingOptions>(options => { options.QueryStringConverts.Add(typeof(DataSourceLoadOptionsBase), typeof(DataSourceLoadOptionsBaseToQueryString)); options.QueryStringConverts.Add(typeof(SummaryInfo[]), typeof(DataSourceLoadOptionsBaseSummaryInfoToQueryString)); });

    DataSourceLoadOptionsBase 不会进行转换 但是SummaryInfo 可以 为什么?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    因为DataSourceLoadOptionsBase 不作为参数, SummaryInfo 是参数, 具体你看JSON的内容就知道了.

  • User Avatar
    0
    mc86 created

    @mailming 谢谢 筛选器已经可以使用了 但是有个问题 DataSourceLoadOptionsBase 中有2个属性都是SummaryInfo 类型的 用转换器的话只能添加一个类型, SummaryInfo a; SummaryInfo b; ulr只能像这样 “xxx/xxxx/a=[SummaryInfo ]”或者 “xxx/xxxx/a=[SummaryInfo ]” 有办法把在转换事件中获取属性名称吗?或者更改下转换器 在调用时将属性名称传入 或者接受自定义?


    另外 如果我把API 更改成POST方法 是否可以把DataSourceLoadOptionsBase 直接传递给接口?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer
    1. 你可以重写ClientProxyUrlBuilder服务. 下个版本会考虑. https://github.com/abpframework/abp/issues/11047
    2. Post会尝试对DataSourceLoadOptionsBase 进行JSON序列化
  • User Avatar
    0
    mc86 created

    非常感谢

Made with ❤️ on ABP v9.1.0-preview. Updated on December 05, 2024, 12:19