Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# Web Service Exception

Status
Not open for further replies.

seanhauv

Programmer
Aug 15, 2008
4
ZA
Hi All

I have a C# web service to create AP Payments, it runs with no problem on my XP dev environment, but when running on a W2k3 server with the same SQL DB, i get an exception "Object reference not set to an instance of an object." on the line
apPaymentBatchFields.FieldByName("PAYMTYPE").SetValue("PY", false);

Thanks
Sean
 
This is how the views are declared and composed,

apPaymentBatch = mDBLinkCmpRW.OpenView("AP0030");
apPaymentBatchFields = apPaymentBatch.Fields;

apPaymentHeader = mDBLinkCmpRW.OpenView("AP0031");
apPaymentHeaderFields = apPaymentHeader.Fields;

apPaymentDetail = mDBLinkCmpRW.OpenView("AP0032");
apPaymentDetailFields = apPaymentDetail.Fields;

apPaymentDetail2 = mDBLinkCmpRW.OpenView("AP0033");
apPaymentDetailFields = apPaymentDetail.Fields;

apPaymentDetail3 = mDBLinkCmpRW.OpenView("AP0034");
apPaymentDetailFields = apPaymentDetail.Fields;

apPaymentOpt = mDBLinkCmpRW.OpenView("AP0406");
apPaymentOptFields = apPaymentOpt.Fields;

apPaymentPost = mDBLinkCmpRW.OpenView("AP0040");
apPaymentPostFields = apPaymentPost.Fields;

apPaymentBatch.Compose(new View[] { apPaymentHeader });

apPaymentHeader.Compose(new View[] { apPaymentBatch, apPaymentDetail, apPaymentDetail2, apPaymentOpt });

apPaymentDetail2.Compose(new View[] { apPaymentHeader, apPaymentDetail3 });

apPaymentDetail3.Compose(new View[] { apPaymentDetail2 });

apPaymentDetail.Compose(new View[] { apPaymentHeader });

apPaymentOpt.Compose(new View[] { apPaymentHeader });
 
Try one of two things.

On the 2k3 server try sharing the common files sage, for the web service.

Check the references in the project that you do reference the correct version of the dll's
 
I have redone my references and made sure they are using common files/Sage dll's, but still the same error.
 
Hi, here is my web service..doing payments. It works on w2k3 server...

[WebMethod(Description = "This method is used to insert a payment into ACCPAC.")]
public string Set_Payment(string _Version,string _Username,string _Password,string _Company,
DateTime DATEBTCH,
string BATCHDESC,
string TEXTRMIT,
string IDVEND,
string TXTRMITREF,
string IDINVCMTCH,
string IDACCT,
decimal AMTDISTTC,
string GLDESC)
{

ACCPAC.Advantage.Session AccSession = new ACCPAC.Advantage.Session();
AccSession.Init("", "AP", "AP3100", _Version);
DateTime fiscalDate = DateTime.Parse("08/31/2007");

AccSession.Open(_Username, _Password, _Company, fiscalDate, 0);

ACCPAC.Advantage.DBLink PmtCompLink = AccSession.OpenDBLink(ACCPAC.Advantage.DBLinkType.Company, ACCPAC.Advantage.DBLinkFlags.ReadWrite);
ACCPAC.Advantage.DBLink PmtSysLink = AccSession.OpenDBLink(ACCPAC.Advantage.DBLinkType.System, ACCPAC.Advantage.DBLinkFlags.ReadWrite);

if (Accpac_Validation.Validate_Vendor(_Version, _Username, _Password, _Company, PmtCompLink, IDVEND) == false)
{
PmtCompLink.Dispose();
PmtSysLink.Dispose();
AccSession.Dispose();
return Accpac_Results.Get_Result(false, "The vendor does not exist");

}

if (Accpac_Validation.Validate_GL_Account(_Version, _Username, _Password, _Company, PmtCompLink, IDACCT) == false)
{
PmtCompLink.Dispose();
PmtSysLink.Dispose();
AccSession.Dispose();
return Accpac_Results.Get_Result(false, "The GL account does not exist");
}

if (Accpac_Validation.Validate_Document_Unique(_Version, _Username, _Username, _Company, PmtCompLink, IDINVCMTCH, IDVEND) == false)
{
PmtCompLink.Dispose();
PmtSysLink.Dispose();
AccSession.Dispose();
return Accpac_Results.Get_Result(false, "The document number must be unique");
}


#region DeclareViews

ACCPAC.Advantage.View APPaymentBatch = PmtCompLink.OpenView("AP0030");
ACCPAC.Advantage.View APPaymentHeader = PmtCompLink.OpenView("AP0031");//header
ACCPAC.Advantage.View APPaymentDetail1 = PmtCompLink.OpenView("AP0033"); //DETAILVIEWS
ACCPAC.Advantage.View APPaymentDetail2 = PmtCompLink.OpenView("AP0034");
ACCPAC.Advantage.View APPaymentDetail3 = PmtCompLink.OpenView("AP0032");
ACCPAC.Advantage.View APPaymentDetail4 = PmtCompLink.OpenView("AP0048");
ACCPAC.Advantage.View APPaymentDetail5 = PmtCompLink.OpenView("AP0406");

ACCPAC.Advantage.View[] APPaymentBatch1 = new ACCPAC.Advantage.View[1] { APPaymentHeader };
APPaymentBatch.Compose(APPaymentBatch1);

ACCPAC.Advantage.View[] APHeaderBatch = new ACCPAC.Advantage.View[4] { APPaymentBatch, APPaymentDetail3, APPaymentDetail1, APPaymentDetail5 };
APPaymentHeader.Compose(APHeaderBatch);

//Compose detail views.
ACCPAC.Advantage.View[] APDetailBatch1 = new ACCPAC.Advantage.View[3] { APPaymentHeader, APPaymentDetail2, APPaymentDetail4 };
APPaymentDetail1.Compose(APDetailBatch1);
ACCPAC.Advantage.View[] APDetailBatch2 = new ACCPAC.Advantage.View[1] { APPaymentDetail1 };
APPaymentDetail2.Compose(APDetailBatch2);
ACCPAC.Advantage.View[] APDetailBatch3 = new ACCPAC.Advantage.View[1] { APPaymentHeader };
APPaymentDetail3.Compose(APDetailBatch3);
ACCPAC.Advantage.View[] APDetailBatch4 = new ACCPAC.Advantage.View[5] { APPaymentBatch, APPaymentHeader, APPaymentDetail3, APPaymentDetail1, APPaymentDetail2 };
APPaymentDetail4.Compose(APDetailBatch4);
ACCPAC.Advantage.View[] APDetailBatch5 = new ACCPAC.Advantage.View[1] { APPaymentHeader };
APPaymentDetail5.Compose(APDetailBatch5);
#endregion

APPaymentBatch.RecordClear();
APPaymentBatch.Fields.FieldByName("PAYMTYPE").SetValue("PY", false); //batch selector
APPaymentHeader.Fields.FieldByName("BTCHTYPE").SetValue("PY", false); //batch type/
APPaymentDetail3.Fields.FieldByName("BATCHTYPE").SetValue("PY", false);
APPaymentDetail1.Fields.FieldByName("BATCHTYPE").SetValue("PY", false);
APPaymentDetail2.Fields.FieldByName("BATCHTYPE").SetValue("PY", false);
APPaymentBatch.Browse(@"((PAYMTYPE=""PY"") AND ((BATCHSTAT=1) OR (BATCHSTAT=7) OR (BATCHSTAT=8)))", true);

APPaymentBatch.Fields.FieldByName("PAYMTYPE").SetValue("PY", false);
APPaymentBatch.Fields.FieldByName("CNTBTCH").SetValue("0", false);
APPaymentBatch.Fields.FieldByName("DATEBTCH").SetValue(DATEBTCH, false); //create net

APPaymentBatch.RecordCreate(ACCPAC.Advantage.ViewRecordCreate.Insert);
APPaymentHeader.RecordCreate(0);

APPaymentBatch.Fields.FieldByName("BATCHDESC").SetValue(BATCHDESC, false);
APPaymentBatch.Update(); //Create Batch Header
APPaymentBatch.Read(false);

APPaymentHeader.RecordCreate(0);

APPaymentHeader.Fields.FieldByName("TEXTRMIT").SetValue(TEXTRMIT, false);
APPaymentHeader.Fields.FieldByName("RMITTYPE").SetValue("4", false);
APPaymentDetail1.Cancel();

APPaymentHeader.Fields.FieldByName("PROCESSCMD").SetValue("0", false);
APPaymentHeader.Process();

try
{
APPaymentHeader.Fields.FieldByName("IDVEND").SetValue(IDVEND, false);
}
catch (Exception)
{
Remove_Empty_Batch(_Version, _Username, _Password, _Company, APPaymentBatch.Fields.FieldByName("CNTBTCH").Value.ToString());
string xmlresult = Accpac_Results.Get_Result(false, "The vendor does not exist in Accpac", string.Format("CNTBTCH={0}", APPaymentBatch.Fields.FieldByName("CNTBTCH").Value.ToString()));

APPaymentDetail1.Dispose();
APPaymentDetail2.Dispose();
APPaymentDetail3.Dispose();
APPaymentDetail4.Dispose();
APPaymentDetail5.Dispose();
APPaymentHeader.Dispose();
APPaymentBatch.Dispose();
PmtCompLink.Dispose();
PmtSysLink.Dispose();
AccSession.Dispose();

return xmlresult;
}

APPaymentDetail1.Cancel();
APPaymentHeader.Fields.FieldByName("PROCESSCMD").SetValue("0", false);
APPaymentHeader.Process();

APPaymentHeader.Fields.FieldByName("TXTRMITREF").SetValue(TXTRMITREF, false);

try
{
APPaymentHeader.Fields.FieldByName("IDINVCMTCH").SetValue(IDINVCMTCH, false); //matching document number
}
catch (Exception)
{
Remove_Empty_Batch(_Version, _Username, _Password, _Company, APPaymentBatch.Fields.FieldByName("CNTBTCH").Value.ToString());
string xmlresult = Accpac_Results.Get_Result(false, "Matching document number must be unique for the vendor", string.Format("CNTBTCH={0}", APPaymentBatch.Fields.FieldByName("CNTBTCH").Value.ToString()));

APPaymentDetail1.Dispose();
APPaymentDetail2.Dispose();
APPaymentDetail3.Dispose();
APPaymentDetail4.Dispose();
APPaymentDetail5.Dispose();
APPaymentHeader.Dispose();
APPaymentBatch.Dispose();
PmtCompLink.Dispose();
PmtSysLink.Dispose();
AccSession.Dispose();

return xmlresult;

}

APPaymentDetail3.RecordClear();
APPaymentDetail3.RecordCreate(0);

try
{
APPaymentDetail3.Fields.FieldByName("IDACCT").SetValue(IDACCT, false); ///account number
}
catch (Exception)
{
Remove_Empty_Batch(_Version, _Username, _Password, _Company, APPaymentBatch.Fields.FieldByName("CNTBTCH").Value.ToString());
string xmlresult = Accpac_Results.Get_Result(false, "Account Number does not ", string.Format("CNTBTCH={0}", APPaymentBatch.Fields.FieldByName("CNTBTCH").Value.ToString()));

APPaymentDetail1.Dispose();
APPaymentDetail2.Dispose();
APPaymentDetail3.Dispose();
APPaymentDetail4.Dispose();
APPaymentDetail5.Dispose();
APPaymentHeader.Dispose();
APPaymentBatch.Dispose();
PmtCompLink.Dispose();
PmtSysLink.Dispose();
AccSession.Dispose();

return xmlresult;
}

APPaymentDetail3.Fields.FieldByName("AMTDISTTC").SetValue(AMTDISTTC, false); //dist ammount
APPaymentDetail3.Fields.FieldByName("GLREF").SetValue(GLDESC, false); //GL reference

APPaymentDetail3.Insert();

APPaymentDetail3.Fields.FieldByName("CNTLINE").SetValue("-1", false); //line number
APPaymentDetail3.Fields.FieldByName("CNTLINE").SetValue("-1", false); //line number
APPaymentDetail3.Read(false);
APPaymentDetail3.RecordCreate(0);
APPaymentDetail3.Fields.FieldByName("CNTLINE").SetValue("-1", false); //line number
APPaymentDetail3.Read(false);
try
{
APPaymentHeader.Insert();
}
catch (Exception)
{
Remove_Empty_Batch(_Version, _Username, _Password, _Company, APPaymentBatch.Fields.FieldByName("CNTBTCH").Value.ToString());
string xmlresult = Accpac_Results.Get_Result(false, "The mathcing document number must be unique for vendor,payment has not been posted.",
string.Format("CNTBTCH={0}", APPaymentBatch.Fields.FieldByName("CNTBTCH").Value.ToString()));
APPaymentDetail1.Dispose();
APPaymentDetail2.Dispose();
APPaymentDetail3.Dispose();
APPaymentDetail4.Dispose();
APPaymentDetail5.Dispose();
APPaymentHeader.Dispose();
APPaymentBatch.Dispose();
PmtCompLink.Dispose();
PmtSysLink.Dispose();
AccSession.Dispose();

return xmlresult;
}

APPaymentBatch.Read(false);

APPaymentHeader.Fields.FieldByName("CNTENTR").SetValue("0", false); //entry number
APPaymentHeader.RecordCreate(0);

string xmlstring = Accpac_Results.Get_Result(true,"",string.Format("CNTBTCH={0}",APPaymentBatch.Fields.FieldByName("CNTBTCH").Value.ToString()));

APPaymentDetail1.Dispose();
APPaymentDetail2.Dispose();
APPaymentDetail3.Dispose();
APPaymentDetail4.Dispose();
APPaymentDetail5.Dispose();
APPaymentHeader.Dispose();
APPaymentBatch.Dispose();
PmtCompLink.Dispose();
PmtSysLink.Dispose();
AccSession.Dispose();

return xmlstring;
}


Just comment out the catch blocks...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top