我有以下代码
QBSessionManager sessionManager = new QBSessionManager();
RequestProcessor2Class requestProcessor = new RequestProcessor2Class();
try
{
IMsgSetRequest msgSetRequest = sessionManager.CreateMsgSetRequest("US", 13, 0);
msgSetRequest.Attributes.OnError = ENRqOnError.roeStop;
// Query all the customers
ICustomerQuery customerQuery = msgSetRequest.AppendCustomerQueryRq();
customerQuery.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameFilter.MatchCriterion.SetValue(ENMatchCriterion.mcContains);
customerQuery.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameFilter.Name.SetValue(customerName);
inputRequestXML = msgSetRequest.ToXMLString();
requestProcessor.OpenConnection("QBWebSite", "QuickBooks");
ticket = requestProcessor.BeginSession("$Path\\sample_consulting business.qbw",QBFileMode.qbFileOpenDoNotCare);
response = requestProcessor.ProcessRequest(ticket, inputRequestXML);
responseTextbox.Text = response;
当页面回发时,它抛出““BeginSession”方法未被调用或未成功”并且 COMException 是 “[COMException (0x8004040c): 未调用“BeginSession”方法或未成功。]”
我做错了什么。请帮忙
我正在使用带有 .NET 4.0 框架的 quickbooks 14 企业版。我确保在 IIS 中将 32 位标志设置为 true。
最佳答案
如错误所述,您需要在创建请求之前调用 SessionManager 上的 BeginSession。这是我用作模板的连接代码:
QBSessionManager SessionManager = null;
try
{
SessionManager = new QBSessionManager();
SessionManager.OpenConnection2("AppID", "AppName", ENConnectionType.ctLocalQBD);
SessionManager.BeginSession("", ENOpenMode.omDontCare);
IMsgSetRequest MsgRequest = SessionManager.CreateMsgSetRequest("US", 13, 0);
MsgRequest.ClearRequests();
MsgRequest.Attributes.OnError = ENRqOnError.roeStop;
// Create request here ///////////////////////////////////////////
}
catch (Exception ex)
{
// Log or display the error
}
finally
{
if (SessionManager != null)
{
SessionManager.EndSession();
SessionManager.CloseConnection();
SessionManager = null;
}
}
关于c# - "BeginSession"方法未被调用或未成功 - QBFC SDK12 和 ASP.NET 网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20877440/