我传入的对象已经被转换为完全成型的QBO客户实体。我想使用AddAsync(IEntity)方法,因为它使用它的ID(或错误)从QBO返回相同的对象。
使用下面的代码,我可以看到它成功地将对象添加到QBO,但我的回调方法永远不会被调用,我只看到以下两个DataService错误消息和输出中的System.dll错误消息:
类型' System.NullReferenceException'的第一次机会异常。发生在Intuit.Ipp.DataService.dll中 类型' System.NullReferenceException'的第一次机会异常。发生在Intuit.Ipp.DataService.dll中 类型' System.NullReferenceException'的第一次机会异常。发生在System.dll
中
这是我的代码:
public void Add([NotNull] Sales.Customer input)
{
try
{
_customer = input;
var qboInput = QboCustomerTranslate.Current.ToQuickbooksModel(input);
QboAuth.AuthService.OnAddAsyncCompleted += OnAddCallBackUpdateQboId;
QboAuth.AuthService.AddAsync(qboInput);
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
public void OnAddCallBackUpdateQboId(object sender, CallCompletedEventArgs<IEntity> e)
{
if (e.Error != null)
{
if (e.Entity != null)
{
var customer = e.Entity as Customer;
if (customer != null)
{
using (var db = DatabaseManager.Current.NewDatabase())
{
_customer.Notes = e.Error.Message;
if (!customer.Id.IsEmpty())
{
_customer.QuickbooksId = customer.Id.AsInt();
}
_customer.Save();
}
}
}
}
else
{
if (e.Entity != null)
{
var customer = e.Entity as Customer;
if (customer != null)
{
using (var db = DatabaseManager.Current.NewDatabase())
{
if (!customer.Id.IsEmpty())
{
_customer.QuickbooksId = customer.Id.AsInt();
}
}
}
}
}
}
我的请求Json看起来像:
{
"BillAddr": {
"Line1": "77 TestStreet",
"Line2": "",
"City": "TestingsVilleTown",
"Country": "USA",
"CountrySubDivisionCode": "TT",
"PostalCode": "77887"
},
"GivenName": "TFirst",
"FamilyName": "TLast",
"CompanyName": "Test22",
"DisplayName": "Test22",
"PrimaryPhone": {
"DeviceType": "Primary",
"FreeFormNumber": "7778884567"
},
"PrimaryEmailAddr": {
"Address": "Test22@Test.com"
}
}
我的回答Json看起来像:
{
"Customer": {
"Taxable": false,
"BillAddr": {
"Id": "9495",
"Line1": "77 TestStreet",
"City": "TestingsVilleTown",
"Country": "USA",
"CountrySubDivisionCode": "TT",
"PostalCode": "77887",
"Lat": "INVALID",
"Long": "INVALID"
},
"Job": false,
"BillWithParent": false,
"Balance": 0,
"BalanceWithJobs": 0,
"PreferredDeliveryMethod": "Print",
"domain": "QBO",
"sparse": false,
"Id": "7291",
"SyncToken": "0",
"MetaData": {
"CreateTime": "2014-03-12T10:06:12-07:00",
"LastUpdatedTime": "2014-03-12T10:06:12-07:00"
},
"GivenName": "TFirst",
"FamilyName": "TLast",
"FullyQualifiedName": "Test22",
"CompanyName": "Test22",
"DisplayName": "Test22",
"PrintOnCheckName": "Test22",
"Active": true,
"PrimaryPhone": {
"FreeFormNumber": "7778884567"
},
"PrimaryEmailAddr": {
"Address": "Test22@Test.com"
}
},
"time": "2014-03-12T10:06:11.796-07:00"
}
- 编辑 -
这些似乎是来自Tracelog的相关行:
WebDev.WebServer40.exe Information: 0 : Info -- 03-13-2014 15:23:37 -- - 0 - Void AddAsyncompleted(System.Object, Intuit.Ipp.Core.AsyncCallCompletedEventArgs) - Finished Executing event AddAsyncompleted in AsyncService object.
WebDev.WebServer40.exe Information: 0 : Info -- 03-13-2014 15:23:37 -- - 0 - Void AddAsyncCompleted(System.Object, Intuit.Ipp.Core.CallCompletedEventArgs`1[Intuit.Ipp.Data.IEntity]) - Finished Executing Method add Async.
WebDev.WebServer40.exe Error: 0 : Error -- 03-13-2014 15:23:37 -- - 0 - Void AddAsyncompleted(System.Object, Intuit.Ipp.Core.AsyncCallCompletedEventArgs) - Intuit.Ipp.Exception.IdsException: Object reference not set to an instance of an object.
WebDev.WebServer40.exe Information: 0 : Info -- 03-13-2014 15:23:37 -- - 0 - Void AddAsyncCompleted(System.Object, Intuit.Ipp.Core.CallCompletedEventArgs`1[Intuit.Ipp.Data.IEntity]) - Finished Executing Method add Async.
简单修复 - 我遇到了这个问题,因为我没有存储我的DataService。
答案 0 :(得分:0)
DataService.DataService service = new DataService.DataService(context);
bool isAdded = false;
// Used to signal the waiting test thread that a async operation have completed.
System.Threading.ManualResetEvent manualEvent = new ManualResetEvent(false);
// Async callback events are anonomous and are in the same scope as the test code,
// and therefore have access to the manualEvent variable.
service.OnAddAsyncCompleted += (sender, e) =>
{
isAdded = true;
manualEvent.Set();
if (e.Error != null)
{
exp = e.Error;
}
if (exp == null)
{
if (e.Entity != null)
{
actual = (T)e.Entity;
}
}
};
// Call the service method
service.AddAsync(entity);
manualEvent.WaitOne(30000, false); Thread.Sleep(10000);
manualEvent.Reset();
以上是使用匿名类型的示例。看看这是否有帮助!