QuickBooks 检索客户失败
QuickBooks Retrieve of Customers Fails
我有这个代码:
protected readonly IMsgSetRequest RequestMsgSet = null;
protected IMsgSetResponse ResponseMsgSet = null;
public string GetAllCustomer(bool IsActiveOnly = true)
{
RequestMsgSet.ClearRequests();
ICustomerQuery CustomerQueryRq = RequestMsgSet.AppendCustomerQueryRq();
if (IsActiveOnly)
{
if (CustomerQueryRq != null)
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(
ENActiveStatus.asActiveOnly);
}
else {
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(ENActiveStatus.asAll);
}
ResponseMsgSet = SessionManager.DoRequests(RequestMsgSet);
return(ResponseMsgSet.ToXMLString());
}
Console.WriteLine(GetAllCustomer());
它returns这个:
<?xml version="1.0" ?>
<QBXML>
<QBXMLMsgsRs>
<CustomerQueryRs requestID="0" statusCode="1000" statusSeverity="Error" statusMessage="There has been an internal error when processing the request." />
</QBXMLMsgsRs>
</QBXML>
我怀疑 DoRequests 内存不足,因为我有 110,000 个客户。
如何确认 DoRequests 运行 内存不足?
如何重写此代码以使用更少的内存?
您可以通过过滤获取数据,例如:名称范围(a-i、j-r 比 s-z)过滤器、日期范围过滤器、名称以过滤器开头以及其他一些过滤器。
此外,这可用于仅获取您想要的内容,例如:FullName 和 AccountNumber.
这样你可能会消耗更少的内存。看看下面的示例代码:
public IList<CustomerModelQB> GetAllCustomer(string fromName = "a", string toName = "z", bool IsActiveOnly = true)
{
RequestMsgSet.ClearRequests();
ICustomerQuery CustomerQueryRq = RequestMsgSet.AppendCustomerQueryRq();
if (IsActiveOnly)
{
if (CustomerQueryRq != null)
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(
ENActiveStatus.asActiveOnly);
}
else
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(ENActiveStatus.asAll);
//CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.MaxReturned.SetValue(3);
//Set field value for FromName
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameRangeFilter.FromName.SetValue(fromName);
//Set field value for ToName
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameRangeFilter.ToName.SetValue(toName);
CustomerQueryRq.IncludeRetElementList.Add("FullName");
CustomerQueryRq.IncludeRetElementList.Add("AccountNumber");
ResponseMsgSet = SessionManager.DoRequests(RequestMsgSet);
return WalkCustomerQuery(ResponseMsgSet);
}
此外,您可以参考 this 按字母顺序排列的问题。
我有这个代码:
protected readonly IMsgSetRequest RequestMsgSet = null;
protected IMsgSetResponse ResponseMsgSet = null;
public string GetAllCustomer(bool IsActiveOnly = true)
{
RequestMsgSet.ClearRequests();
ICustomerQuery CustomerQueryRq = RequestMsgSet.AppendCustomerQueryRq();
if (IsActiveOnly)
{
if (CustomerQueryRq != null)
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(
ENActiveStatus.asActiveOnly);
}
else {
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(ENActiveStatus.asAll);
}
ResponseMsgSet = SessionManager.DoRequests(RequestMsgSet);
return(ResponseMsgSet.ToXMLString());
}
Console.WriteLine(GetAllCustomer());
它returns这个:
<?xml version="1.0" ?>
<QBXML>
<QBXMLMsgsRs>
<CustomerQueryRs requestID="0" statusCode="1000" statusSeverity="Error" statusMessage="There has been an internal error when processing the request." />
</QBXMLMsgsRs>
</QBXML>
我怀疑 DoRequests 内存不足,因为我有 110,000 个客户。
如何确认 DoRequests 运行 内存不足?
如何重写此代码以使用更少的内存?
您可以通过过滤获取数据,例如:名称范围(a-i、j-r 比 s-z)过滤器、日期范围过滤器、名称以过滤器开头以及其他一些过滤器。
此外,这可用于仅获取您想要的内容,例如:FullName 和 AccountNumber.
这样你可能会消耗更少的内存。看看下面的示例代码:
public IList<CustomerModelQB> GetAllCustomer(string fromName = "a", string toName = "z", bool IsActiveOnly = true)
{
RequestMsgSet.ClearRequests();
ICustomerQuery CustomerQueryRq = RequestMsgSet.AppendCustomerQueryRq();
if (IsActiveOnly)
{
if (CustomerQueryRq != null)
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(
ENActiveStatus.asActiveOnly);
}
else
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(ENActiveStatus.asAll);
//CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.MaxReturned.SetValue(3);
//Set field value for FromName
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameRangeFilter.FromName.SetValue(fromName);
//Set field value for ToName
CustomerQueryRq.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameRangeFilter.ToName.SetValue(toName);
CustomerQueryRq.IncludeRetElementList.Add("FullName");
CustomerQueryRq.IncludeRetElementList.Add("AccountNumber");
ResponseMsgSet = SessionManager.DoRequests(RequestMsgSet);
return WalkCustomerQuery(ResponseMsgSet);
}
此外,您可以参考 this 按字母顺序排列的问题。