2

我想插入多个客户对象我点击了这个链接https://developer.intuit.com/docs/0025_quickbooksapi/0055_devkits/0100_ipp_.net_devkit/0300_asynchronous_calls/2_batch_process但出现以下错误 - “您只能在时间。请再试一次。”


发布我的代码:

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Web;
using Intuit.Ipp.Core;
using Intuit.Ipp.Security;
using Intuit.Ipp.Services;
using HelloIntuitAnywhere.Utilities;
using Intuit.Ipp.Data.Qbo;
using Intuit.Ipp.Data.Extensions;
using System.Linq;
using System.IO;
using Intuit.Ipp.Data;

namespace HelloIntuitAnywhere
{
    public partial class BatchRequest : System.Web.UI.Page
    {
        public delegate IntuitBatchResponse DelegateBatchCompleted(IntuitBatchRequest batchRequest);
        protected void Page_Load(object sender, EventArgs e)
        {

            if (HttpContext.Current.Session.Keys.Count > 0)
            {
                String realmId = HttpContext.Current.Session["realm"].ToString();
                String accessToken = HttpContext.Current.Session["accessToken"].ToString();
                String accessTokenSecret = HttpContext.Current.Session["accessTokenSecret"].ToString();
                String consumerKey = ConfigurationManager.AppSettings["consumerKey"].ToString(CultureInfo.InvariantCulture);
                String consumerSecret = ConfigurationManager.AppSettings["consumerSecret"].ToString(CultureInfo.InvariantCulture);
                IntuitServicesType intuitServiceType = (IntuitServicesType)HttpContext.Current.Session["intuitServiceType"];

                OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
                ServiceContext context = new ServiceContext(oauthValidator, realmId, intuitServiceType);
                DataServices commonService = new DataServices(context);

                try
                {
                    switch (intuitServiceType)
                    {
                        case IntuitServicesType.QBO:

                            IntuitBatchRequest batchRequest = new IntuitBatchRequest();
                            batchRequest.BatchItem = new BatchItemRequest[10];

                            for (int i = 0; i < 10; i++)
                            {
                                Item itm1 = CreateItem("it8" + i.ToString());
                                string guid = Guid.NewGuid().ToString("N");
                                guid = guid.Substring(0, 30);
                                guid = i.ToString();
                                BatchItemRequest itm1BatchItem = new BatchItemRequest();
                                itm1BatchItem.bId = guid;
                                itm1BatchItem.Item = itm1;
                                itm1BatchItem.operation = OperationEnum.create;
                                itm1BatchItem.operationSpecified = true;
                                batchRequest.BatchItem[i] = itm1BatchItem;
                            }



                            //IntuitBatchResponse batchResponse = commonService.ExecuteBatch<IntuitBatchRequest>(batchRequest);
                            try
                            {
                                DelegateBatchCompleted delegateBatch = new DelegateBatchCompleted(commonService.ExecuteBatch<IntuitBatchRequest>);
                                IAsyncResult result = delegateBatch.BeginInvoke(batchRequest, new AsyncCallback(CallbackMethod), delegateBatch);
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }


                            break;

                        default:
                            throw new Exception("Data Source not defined.");
                    }


                }
                catch
                {
                    throw;
                }
            }
        }

        private Intuit.Ipp.Data.Qbo.Item CreateItem(string str)
        {
            Intuit.Ipp.Data.Qbo.Item item = new Intuit.Ipp.Data.Qbo.Item();

            item.Desc = str + "Test Desc";
            item.Name = str + "Test Name";
            item.Taxable = true;
            item.TaxableSpecified = true;
            item.ExternalKey = new Intuit.Ipp.Data.Qbo.IdType() { idDomain = Intuit.Ipp.Data.Qbo.idDomainEnum.QBO, Value = str + "123" };
            item.UnitPrice = new Intuit.Ipp.Data.Qbo.Money() { Amount = 6, AmountSpecified = true, CurrencyCode = Intuit.Ipp.Data.Qbo.currencyCode.AED, CurrencyCodeSpecified = false };

            item.IncomeAccountRef = new Intuit.Ipp.Data.Qbo.AccountRef() { AccountId = new Intuit.Ipp.Data.Qbo.IdType() { idDomain = Intuit.Ipp.Data.Qbo.idDomainEnum.QBO, Value = "1" }, AccountType = Intuit.Ipp.Data.Qbo.AccountTypeEnum.Asset, AccountTypeSpecified = true };

            item.Type = Intuit.Ipp.Data.Qbo.ItemTypeEnum.Assembly;

            return item;
        }

        static void CallbackMethod(IAsyncResult result)
        {
            DelegateBatchCompleted delegateBatch = (DelegateBatchCompleted)result.AsyncState;
            IntuitBatchResponse batchResponse = delegateBatch.EndInvoke(result);
        }


    }
}
4

1 回答 1

1

错误信息非常明确:Quickbooks API 一次只允许编辑一个客户。

他们可能会锁定 Customer 表,因为业务层或底层数据模型都不支持并发编辑。

鉴于此限制,我看不到解决此问题的方法。

它们允许您异步调用同步方法,因此您不必阻塞直到方法完成,但这并不意味着您可以同时进行两个客户编辑。但是,您可以在编辑完成时进行其他工作。

于 2013-06-21T07:16:55.180 回答