我已经很久没有使用 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);
}
}