Here is the code: I am getting the error when submitting the data. No Error coming when reading the data. This is small service upgrade from version 8 to 10.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.EnterpriseServices;
using Microsoft.Dynamics.GP.eConnect;
using System.Xml;
namespace eConnect
{
/// <summary>
/// Web service for Great Plains integration via eConnect
/// </summary>
public class Poster : System.Web.Services.WebService
{
String ConnectionString;
XmlDocument xmlDoc;
public Poster()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}
#region Component Designer generated code
//Required by the Web Services Designer
private IContainer components = null;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
[ WebMethod(TransactionOption=TransactionOption.RequiresNew) ]
public eConnectResult PostDoc(string xmldoc2)
{
// eConnectResult r = new eConnectResult("");
// ContextUtil.DisableCommit();
// ExecProcsXML.ExecStoredProcedure8Class test = new ExecProcsXML.ExecStoredProcedure8Class();
// try
// {
// r.result = test.ExecStoredProc(xmldoc,System.Configuration.ConfigurationSettings.AppSettings
[ "GPConnectionString"],ref r.errState,ref r.errString,ref r.soapMessage);
// if (test.eConnectErrorState > 0)
// {
// foreach (object o in test.ErrorCodes)
// r.errString += o.ToString();
// ContextUtil.SetAbort();
// }
// else
// ContextUtil.SetComplete();
// }
// catch
// {
// ContextUtil.SetAbort();
//// throw;
// }
// return r;
xmlDoc.PreserveWhitespace = true;
eConnectResult r = new eConnectResult("");
ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["GPSqlConnectionString"];
eConnectMethods eConnObject = new eConnectMethods();
try
{
xmlDoc.LoadXml(xmldoc2);
r.result = eConnObject.eConnect_EntryPoint(ConnectionString,
EnumTypes.ConnectionStringType.OleDB, xmlDoc.OuterXml, EnumTypes.SchemaValidationType.None, null);
ContextUtil.SetComplete();
}
catch (eConnectException ex)
{
r.errString = ex.Message.ToString();
ContextUtil.SetAbort();
}
catch (System.Data.SqlClient.SqlException ex)
{
foreach (object o in ex.Errors )
r.errString += o.ToString();
ContextUtil.SetAbort();
}
catch (Exception ex)
{
r.errString = ex.Message.ToString();
ContextUtil.SetAbort();
}
return r;
}
[WebMethod(TransactionOption = TransactionOption.RequiresNew)]
public String PostDoc200(string xmldoc2)
{
bool eConnResult = false;
String r;
eConnectMethods eConnObject = new eConnectMethods();
try
{
r = "";
xmlDoc.LoadXml(xmldoc2);
if (IsRequesterDoc(xmlDoc) == true) {
r = eConnObject.eConnect_Requester(ConnectionString,
EnumTypes.ConnectionStringType.OleDB, xmlDoc.OuterXml);
}
else
{
eConnResult = eConnObject.eConnect_EntryPoint(ConnectionString,
EnumTypes.ConnectionStringType.OleDB, xmlDoc.OuterXml, EnumTypes.SchemaValidationType.None, null);
if (eConnResult == true) {
ContextUtil.SetComplete();
} else {
ContextUtil.SetAbort();
}
}
}
catch (eConnectException eConnErr)
{
r= eConnErr.Message;
ContextUtil.SetAbort();
}
catch (ApplicationException ex)
{
r= ex.Message;
ContextUtil.SetAbort();
}
return r;
}
[WebMethod]
public DataSet ReadTable(string table,string columns,string condition)
{
DataSet s = new DataSet();
string sql = "select " + columns + " from " + table;
if (condition != "") sql += " where " + condition;
OleDbConnection con = new OleDbConnection();
//SqlDataAdapter.SqlConnection con = new SqlConnection();
con.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings
["GPSqlConnectionString"];
OleDbCommand cmd = new OleDbCommand(sql,con);
//SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
OleDbDataAdapter ad = new OleDbDataAdapter(cmd);
//SqlDataAdapter ad = new SqlDataAdapter(cmd);
ad.Fill(s,table);
cmd.Connection.Close();
return s;
}
public struct eConnectResult
{
public int errState;
public string errString;
public bool result;
public string soapMessage;
public eConnectResult(string s)
{
errState = 0;
errString = "";
result = false;
soapMessage = "";
}
}
private static bool IsRequesterDoc(XmlDocument doc)
{
//Create an XML node and query the document for the <Outgoing> node
XmlNode RequesterMessage = default(XmlNode);
RequesterMessage = doc.SelectSingleNode("//Outgoing");
//Return False if the <Outgoing> node is not found or its value is not equal to TRUE
//Return True when the <Outgoing> node exists and it's value is equal to TRUE
if (RequesterMessage == null)
{
return false;
}
else
{
if (RequesterMessage.InnerText == "TRUE")
{
return true;
}
else
{
return false;
}
}
}
}
}