我已经很久没有用Blazor编程了,并且遇到了一些序列化问题。在同一个解决方案中,我有一个服务器端的blazor应用程序和一个客户端。我有一个服务器端控制器,它被发送一个ID,然后检索对象的数据,构建对象,然后将对象返回给客户端。这个物体相当大,但最多只有5层深。返回了对象的大部分,但截断了其余部分。我在MVC中也遇到过类似的问题,可以通过更改web.config文件中的maxBufferSize和maxMessageSize来修复它。由于没有web.config文件,我该如何以及在哪里进行更改?序列化内置于JASON
服务器端看起来像
public SalesDeal FindDeal(int dealID, bool lockDeal)
{
SET_EMPLOYEES user = new SET_EMPLOYEES();
SalesControl sControl = SalesData.SalesControls.FindByControlID(dealID, user.CNN);
SalesDeal deal = new SalesDeal { SalesControl = sControl };
try
{
Task[] tasks = new Task[26];
tasks[0] = Task.Factory.StartNew(() => { deal.AHLife = SalesData.AHLife.FindByID(sControl.SALESCONTROL_ID, user.CNN); });
tasks[1] = Task.Factory.StartNew(() => { deal.BankInformation = SalesData.Banks.FindByID(sControl.BANK_ID, user.CNN); });
tasks[2] = Task.Factory.StartNew(() => { deal.Company = SET_COMPANIESManager.FindByID(sControl.COMPANY_ID, user.CNN); });
tasks[3] = Task.Factory.StartNew(() => { deal.FinanceManager = SET_EMPLOYEESManager.FindByID(sControl.FinManager_EMPLOYEE_ID, user.CNN); });
tasks[4] = Task.Factory.StartNew(() => { deal.SalesAdds = SalesData.Adds.FindBySalesControlID(sControl.SALESCONTROL_ID, user.CNN); });
tasks[5] = Task.Factory.StartNew(() => { deal.SalesCommGross = SalesData.CommGross_Data.FindByID(sControl.SALESCONTROL_ID, user.CNN); });
tasks[6] = Task.Factory.StartNew(() => { deal.SalesCustomer = CustomerManager.FindCustomerByID(sControl.CUSTOMER_ID, user.CNN); });
tasks[7] = Task.Factory.StartNew(() => { deal.SalesFinancial = SalesData.Financial.FindByID(sControl.SALESCONTROL_ID, user.CNN); });
tasks[8] = Task.Factory.StartNew(() => { deal.SalesRebates = SalesData.Rebates.FindBySalesControlID(sControl.SALESCONTROL_ID, user.CNN); });
tasks[9] = Task.Factory.StartNew(() => { deal.SalesGap = SalesData.Gap_Data.FindByID(sControl.SALESCONTROL_ID, user.CNN); });
tasks[10] = Task.Factory.StartNew(() => { deal.SalesGapProvider = SalesData.GapProviders.FindByID(sControl.SALESCONTROL_ID, user.CNN); });
tasks[11] = Task.Factory.StartNew(() => { deal.SalesLocCharges = SalesData.LocCharges.FindBySALESCONTROL_ID(sControl.SALESCONTROL_ID, user.CNN); });
tasks[12] = Task.Factory.StartNew(() => { deal.SalesLocParams = SalesData.LocParams.FindByDealerID(sControl.COMPANY_ID, user.CNN); });
tasks[13] = Task.Factory.StartNew(() => { deal.SalesManager = SET_EMPLOYEESManager.FindByID(sControl.SalesManager_EMPLOYEE_ID, user.CNN); });
tasks[14] = Task.Factory.StartNew(() => { deal.SalesRep1 = SET_EMPLOYEESManager.FindByID(sControl.SalesRep1_EMPLOYEE_ID, user.CNN); });
tasks[15] = Task.Factory.StartNew(() => { deal.SalesRep2 = SET_EMPLOYEESManager.FindByID(sControl.Salesrep2_EMPLOYEE_ID, user.CNN); });
tasks[16] = Task.Factory.StartNew(() => { deal.SalesService = SalesData.Service_Data.FindByID(sControl.SALESCONTROL_ID, user.CNN); });
tasks[17] = Task.Factory.StartNew(() => { deal.SalesServiceProvider = SalesData.ServiceProviders.FindByID(sControl.SERVICE_PROVIDER_ID, user.CNN); });
tasks[18] = Task.Factory.StartNew(() => { deal.SalesWarranty = SalesData.WarrantyData.FindByID(sControl.SALESCONTROL_ID, user.CNN); });
tasks[19] = Task.Factory.StartNew(() => { deal.SalesWarrantyProvider = SalesData.WarrantyProvidersData.FindByID(sControl.SERVICE_PROVIDER_ID, user.CNN); });
tasks[20] = Task.Factory.StartNew(() => { deal.SecondaryCustomer = CustomerManager.FindCustomerByID(sControl.SEC_CUSTOMER_ID, user.CNN); });
tasks[21] = Task.Factory.StartNew(() => { deal.Trades = SalesData.UpTrades.FindBySalesControlID(sControl.SALESCONTROL_ID, user.CNN); });
tasks[22] = Task.Factory.StartNew(() => { deal.Vehicle = SalesData.SaleInventory.FindByID(sControl.INVENTORY_ID, user.CNN); });
tasks[23] = Task.Factory.StartNew(() => { deal.SalesPlan = SalesData.CRM_SALES_MENU_Data.FindBySALESCONTROL(sControl.SALESCONTROL_ID, user.CNN); });
tasks[24] = Task.Factory.StartNew(() => { deal.DealCalcValues = SalesData.CalculationValues_Data.FindByID(sControl.SALESCONTROL_ID, user.CNN); });
tasks[25] = Task.Factory.StartNew(() => { deal.GridRates = SalesData.SALES_GRIDRATES_Data.FindBySALESCONTROL_ID(sControl.SALESCONTROL_ID, user.CNN).Values.ToList(); });
Task.WaitAll(tasks);
return deal;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
}
客户端看起来。。。
protected override async Task OnInitializedAsync()
{
string urlString = string.Format("CWSalesDeal/FindDeal?dealid={0}&lockDeal={1}", dealid, true);
try
{
deal = await Http.GetFromJsonAsync<SalesDeal>(urlString);
if (deal == null)
throw new Exception("is null");
controller = new SalesDealController(deal);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + " " + ex?.InnerException?.Message);
}
}
原来我是个白痴。。在浏览了所有的类和子类之后,我终于发现了问题。。有2个属性使用字典而不是列表。不支持字典。感谢收听
您可以尝试用Newtonsoft替换默认的序列化程序:Microsoft.AspNetCore.Mvc.NewtonsoftJson
这解决了许多问题。