I used the Quickbooks SDK because I was developing a import tool for a friend and we didn't have the luxury of buying a 3rd party library.
I started developing it as a web service, but I had to fall back after realizing that, not only does we need to deploy the redistribuable of the Quickbooks SDK on the server, but we also needed Quickbooks itself to be installed. And more often than never, Quickbooks displayed a dialog, which on a server is bad.
As long as that dialog was open, Quickbooks SDK would refuse any connection to it.
I ended up doing it as a pure C# Winform application. From there, its rather strait-forward.
At the heart of the program was a quickbook session class that handled the session and the message
public static class Quickbooks
{
public static QuickbookSession CreateSession()
{
return new QuickbookSession();
}
}
public class QuickbookSession : IDisposable
{
/// <summary>
/// Initializes a new instance of the <see cref="QuickbookSession"/> class.
/// </summary>
internal QuickbookSession()
{
this.SessionManager = new QBSessionManager();
this.SessionManager.OpenConnection2(
ConfigurationManager.AppSettings["QuickbooksApplicationId"],
ConfigurationManager.AppSettings["QuickbooksApplicationName"],
Utils.GetEnumValue<ENConnectionType>(ConfigurationManager.AppSettings["QuickbooksConnectionType"]));
var file = Quickbook.QuickbookDatabaseFilePath;
if (string.IsNullOrEmpty(file))
{
file = ConfigurationManager.AppSettings["QuickbooksDatabaseLocalPath"];
}
this.SessionManager.BeginSession(file, Utils.GetEnumValue<ENOpenMode>(ConfigurationManager.AppSettings["QuickbooksSessionOpenMode"]));
}
/// <summary>
/// Gets the Quickbook session manager that is owning this message.
/// </summary>
public QBSessionManager SessionManager { get; private set; }
public QuickbookMessage CreateMessage()
{
return new QuickbookMessage(this.SessionManager);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
// get rid of managed resources
}
this.SessionManager.EndSession();
this.SessionManager.CloseConnection();
System.Runtime.InteropServices.Marshal.ReleaseComObject(this.SessionManager);
}
}
After that, it was simple a matter of creating a session, creating a message and appending the different query.
using(var session = Quickbooks.CreateSession())
{
// Check if the job already exist
using (var message = session.CreateMessage())
{
var jobQuery = message.AppendCustomerQueryRq();
jobQuery.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameFilter.Name.SetValue("something");
jobQuery.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameFilter.MatchCriterion.SetValue(ENMatchCriterion.mcContains);
var result = message.Send();
// do stuff here with the result
}
}
This code is far from being bullet proof from the many pitfall of Quickbooks. The Quickbooks SDK is also rather slow. For example, retrieving the list of supplier takes about 2 minutes for about 1000 suppliers.