Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Web服务一次只能获取1000行,但总数超过30000行_C#_Web Services - Fatal编程技术网

C# Web服务一次只能获取1000行,但总数超过30000行

C# Web服务一次只能获取1000行,但总数超过30000行,c#,web-services,C#,Web Services,我正在使用Netsuite提供的一些web服务 它只允许我一次获得1000行,然后我需要对下一组1000行执行第二次搜索,以此类推。有一些示例代码,但它只返回第二组行,我不确定如何获取第三、第四行,依此类推 到目前为止,我的代码是: private void getAllCustomers() { // Instantiate a search object for customers. CustomerSearch custSearch = new CustomerSearc

我正在使用Netsuite提供的一些web服务

它只允许我一次获得1000行,然后我需要对下一组1000行执行第二次搜索,以此类推。有一些示例代码,但它只返回第二组行,我不确定如何获取第三、第四行,依此类推

到目前为止,我的代码是:

private void getAllCustomers()
{
    // Instantiate a search object for customers.
    CustomerSearch custSearch = new CustomerSearch();
    CustomerSearchBasic custSearchBasic = new CustomerSearchBasic();


    // Search the customer status which is a list field (16,13,15)
    String statusKeysValue = "16,13,15";
    SearchMultiSelectField status = null;
    if (statusKeysValue != null && !statusKeysValue.Trim().Equals(""))
    {
        status = new SearchMultiSelectField();
        status.@operator = SearchMultiSelectFieldOperator.anyOf;
        status.operatorSpecified = true;
        string[] nskeys = statusKeysValue.Split(new Char[] { ',' });

        RecordRef[] recordRefs = new RecordRef[statusKeysValue.Length];
        for (int i = 0; i < nskeys.Length; i++)
        {
            RecordRef recordRef = new RecordRef();
            recordRef.internalId = nskeys[i];
            recordRefs[i] = recordRef;
        }
        status.searchValue = recordRefs;
        custSearchBasic.entityStatus = status;
    }

    custSearch.basic = custSearchBasic;

    // Invoke search() web services operation
    SearchResult response = _service.search(custSearch);            

     // Process response
    if (response.status.isSuccess)
    {
        // Process the records returned in the response
        // Here I get the first 1000 records
        processGetAllCustomersResponse(response);

        // Since pagination controls what is returned, check to see
        // if there are anymore pages to retrieve.

        SearchResult seachMoreResult = searchMore(response);

        if (seachMoreResult != null)
        {
            // Process response
            if (seachMoreResult.status.isSuccess)
            {
                // Here I get the next 1000 records
                    processGetAllCustomersResponse(seachMoreResult);

                // My problem now is to get the third set of 1000 customers, then the fourth and so on till I got all 34500 something
            }
            else
            {

            }

        }
    }
    else
    {

    }
}

private SearchResult searchMore(SearchResult response)
{
    // Keep getting pages until there are no more pages to get
    while (response.totalRecords > (response.pageSize * response.pageIndex))
    {
        return _service.searchMore(response.pageIndex + 1);
    }

    return null;
}
private void getAllCustomers()
{
//为客户实例化搜索对象。
CustomerSearch custSearch=新CustomerSearch();
CustomerSearchBasic custSearchBasic=新CustomerSearchBasic();
//搜索作为列表字段的客户状态(16,13,15)
字符串statusKeyValue=“16,13,15”;
SearchMultiSelectField状态=空;
if(statusKeysValue!=null&&!statusKeysValue.Trim()等于(“”)
{
状态=新建SearchMultiSelectField();
状态。@operator=SearchMultiSelectFieldOperator.anyOf;
status.operatorSpecified=true;
字符串[]nskeys=statusKeysValue.Split(新字符[]{',});
RecordRef[]recordRefs=新的RecordRef[StatusKeyValue.Length];
for(int i=0;i(response.pageSize*response.pageIndex))
{
return _service.searchMore(response.pageIndex+1);
}
返回null;
}

在ProcessGetAllCustomerResponse中,我只需将行插入另一个工作正常的数据库中(除了没有获得我想要的所有行)。

我更改了SearchMore函数,现在它将返回所有响应的列表,您需要相应地更改getAllCustomer函数

编辑:同时更新getAllCustomer

 private void getAllCustomers()
    {
        // Instantiate a search object for customers. 
        CustomerSearch custSearch = new CustomerSearch();
        CustomerSearchBasic custSearchBasic = new CustomerSearchBasic();


        // Search the customer status which is a list field (16,13,15) 
        String statusKeysValue = "16,13,15";
        SearchMultiSelectField status = null;
        if (statusKeysValue != null && !statusKeysValue.Trim().Equals(""))
        {
            status = new SearchMultiSelectField();
            status.@operator = SearchMultiSelectFieldOperator.anyOf;
            status.operatorSpecified = true;
            string[] nskeys = statusKeysValue.Split(new Char[] { ',' });

            RecordRef[] recordRefs = new RecordRef[statusKeysValue.Length];
            for (int i = 0; i < nskeys.Length; i++)
            {
                RecordRef recordRef = new RecordRef();
                recordRef.internalId = nskeys[i];
                recordRefs[i] = recordRef;
            }
            status.searchValue = recordRefs;
            custSearchBasic.entityStatus = status;
        }

        custSearch.basic = custSearchBasic;

        // Invoke search() web services operation 
        SearchResult response = _service.search(custSearch);

        // Process response 
        if (response.status.isSuccess)
        {
            // Process the records returned in the response 
            // Here I get the first 1000 records 
            processGetAllCustomersResponse(response);

            // Since pagination controls what is returned, check to see 
            // if there are anymore pages to retrieve. 

            List<SearchResult> seachMoreResult = searchMore(response);

            if (seachMoreResult != null)
            {
                foreach (SearchResult sr in seachMoreResult)
                {
                    if (sr.status.isSuccess)
                    {
                        // Here I get the next 1000 records 
                        processGetAllCustomersResponse(sr);

                        // My problem now is to get the third set of 1000 customers, then the fourth and so on till I got all 34500 something 
                    }
                    else
                    {

                    }
                }
                // Process response 


            }
        }
        else
        {

        }
    }

private IEnumerable<SearchResult> searchMore(SearchResult response)
    {
        // Keep getting pages until there are no more pages to get    
        int tempTotalRecords = response.totalRecords;
        int pageSize = response.pageSize * response.pageIndex;
        SearchResult tempResponse = null;
        List<SearchResult> records = new List<SearchResult>();
        while (tempTotalRecords > (pageSize))
        {
            SearchResult tempResponse = _service.searchMore(response.pageIndex + 1); 

            if (tempResponse.totalRecords > tempResponse.pageSize * tempResponse.pageIndex)
            {
                tempTotalRecords = tempResponse.totalRecords;
                pageSize = tempResponse.pageSize * tempResponse.pageIndex;
                records.Add(response);
            }
            else
                records.Add(response);


        }

        return records;
    }      
private void getAllCustomers()
{
//为客户实例化搜索对象。
CustomerSearch custSearch=新CustomerSearch();
CustomerSearchBasic custSearchBasic=新CustomerSearchBasic();
//搜索作为列表字段的客户状态(16,13,15)
字符串statusKeyValue=“16,13,15”;
SearchMultiSelectField状态=空;
if(statusKeysValue!=null&&!statusKeysValue.Trim()等于(“”)
{
状态=新建SearchMultiSelectField();
状态。@operator=SearchMultiSelectFieldOperator.anyOf;
status.operatorSpecified=true;
字符串[]nskeys=statusKeysValue.Split(新字符[]{',});
RecordRef[]recordRefs=新的RecordRef[StatusKeyValue.Length];
for(int i=0;i    /// <summary>
    /// Return the list of time bills whose last modified date is within 
    /// the indicated date range.
    /// </summary>
    /// <param name="from">Required from date</param>
    /// <param name="to">Optional to date</param>
    /// <returns>List of time bills</returns>
    public IEnumerable<TimeBill> GetTimeBills(DateTime from, DateTime to)
    {
        _log.Debug(String.Format("Enter TimeBill(DateTime from='{0}', DateTime to='{1}')", from, to));

        // Build search criteria.
        TimeBillSearch search = new TimeBillSearch();
        TimeBillSearchBasic searchBasic = new TimeBillSearchBasic();
        SearchDateField searchDateField = new SearchDateField();
        searchDateField.@operator = SearchDateFieldOperator.within;
        searchDateField.operatorSpecified = true;
        searchDateField.searchValue = from;
        searchDateField.searchValueSpecified = true;
        searchDateField.searchValue2 = to;
        searchDateField.searchValue2Specified = true;
        searchBasic.dateCreated = searchDateField;
        search.basic = searchBasic;

        return this.Get<TimeBill>(search);
    }  

    /// <summary>
    /// Perform a paged search and convert the returned record to the indicated type.
    /// </summary>
    private IEnumerable<T> Get<T>(SearchRecord searchRecord)
    {
        _log.Debug("Enter Get<T>(SearchRecord searchRecord)");

        // This is returned.
        List<T> list = new List<T>();

        // The suitetalk service return this.
        SearchResult result = null;

        using (ISuiteTalkService service = SuiteTalkFactory.Get<SuiteTalkService>())
        {
            do
            {
                // .search returns the first page of data.
                if (result == null)
                {
                    result = service.search(searchRecord);
                }
                else // .searchMore returns the next page(s) of data.
                {
                    result = service.searchMoreWithId(result.searchId, result.pageIndex + 1);
                }

                if (result.status.isSuccess)
                {
                    foreach (Record record in result.recordList)
                    {
                        if (record is T)
                        {
                            list.Add((T)Convert.ChangeType(record, typeof(T)));
                        }
                    }
                }
            }
            while (result.pageIndex < result.totalPages);
        }
        return list;
    }