
Hi,
I am using Ax4 and Visual studio 2010 for Business connector.
I have create a class in ax and a static method.
as I run the business connector class in visual studio am getting the below error . Please let me know what is going wrong :
Below is my Business Connector Class:
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Drawing;
//using System.Threading.Tasks;
using Bcn = Microsoft.Dynamics.BusinessConnectorNet;
namespace GenerateQuotation
{
class GenerateQuote
{
System.Net.NetworkCredential nc = new System.Net.NetworkCredential("karad","Pioneer1");
string sRes;
public string sID = "QJ-00098483";
string strUserName = "karad";
public string sAxConfig;
public string sComp;
public string sLang;
public string sObjSer;
//[STAThread]
//static void Main(string[] args)
// Create the .NET Business Connector objects.
public string connect()
{
Bcn.Axapta ax;
ax = new Bcn.Axapta();
sAxConfig = @"C:\Users\karya-radhikak\Documents\Visual Studio 2010\Projects\GenerateQuotation\GenerateQuotation\bin\Debug\app.config";
sComp = "pmf";
sLang = "USD";
sObjSer = "PMFCGRB23:95";
object o;
bool b;
// ax = new Axapta();
try
{
// Login to Microsoft Dynamics Ax.
//ax.LogonAs(strUserName,"pioneermetal.net", "", nc, "", "", "", "");
ax.Logon(sComp, sLang, sObjSer, sAxConfig);
// ax.Logon(null, null, null, null);
}
catch (Exception e)
{
MessageBox.Show("Exception Caught :" + e);
//or Axapta logon: {0}", e.Message);
// return e;
}
// Logon was successful.
try
{
// Call a static class method.
// In this example, call SysLabel::labelId2String2
// to determine the label string for a particular label ID.
// o = ax.CallStaticClassMethod("AXBusinessConnector","callBusinessLogic", sID);
//Console.WriteLine("The Student Name for {0} is {1}.",
//sID, o.ToString());
//return o.ToString();
sRes = ax.CallStaticClassMethod("pmf_GenerateQuotationRpt ", "callBusinessLogic", this.sID).ToString();
ax.Logoff();
}
catch (Exception e)
{
// Console.WriteLine("An error has been encountered during
// CallStaticClassMethod: {0}", e.Message);
b = ax.Logoff();
//return;
}
// Display the returned string.
// Console.WriteLine("The label string for {0} is {1}.",
// sID, o.ToString());
return sRes;
// Log off from Microsoft Dynamics AX.
b = ax.Logoff();
}
}
}
Please do the needful
Thanks ,
Mania
*This post is locked for comments
I have the same question (0)Just to add above . Please find the app.config code as below:
<?xml version="1.0"?> <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup> </configuration>