Hi All,
I have created a class in AX. Then have created a .Net Business Connector .
Actually the requirement is to create Sales Quotation report in PDF format and to save it in a share drive. For this I have created a class in AX . When I call the class through the .Net Business Connector it is perfectly creating the report in PDF format and saving it in the share drive as required. Then I have created a visual studio console app and calling the .Net Business Connector from it which will be calling the AX class , Now the problem is it is creating the report in the share drive but with just 1kb , I mean it contains no data in it when tried to open getting error as it not a valid PDF file.
Please let me know why it is working correctly when I am calling the AX class via .Net Business Connector directly and why it is not working when the same AX class is called via a Console app.
Please find my Below Codes:
(1) Visual Studio Console App Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Dynamics.BusinessConnectorNet; namespace GenerateQuote { public class Program { static void Main(string[] args) { Program p = new Program(); p.NonStaticMethod(); //objGenQuote.sUserName = username; //objGenQuote.sPassword = password; //objGenQuote.sID = quotation; } public void NonStaticMethod() { string sUserName, sRes, sID; bool b; Console.WriteLine("Enter User Name :"); string username = Console.ReadLine(); Console.WriteLine("Enter Password :"); string password = Console.ReadLine(); Console.WriteLine("Pass the Quotation No :"); string quotation = Console.ReadLine(); SalesQuotation objGenQuote = new SalesQuotation(); if(objGenQuote != null) { var path = objGenQuote.connect(username,password,quotation); Console.WriteLine("Quote PDF Generated Successfully at :" + path); Console.ReadLine(); } } /* //Console.ReadLine(); CreateQuotationPDF objGenQuote = new CreateQuotationPDF(); //objGenQuote.sUserName = username; //objGenQuote.sPassWord = password; //objGenQuote.sID = quotation; objGenQuote.Logon(username, password, quotation); string path = objGenQuote.Logon(username, password,quotation); //var path = objGenQuote.connect(quotation); */ } }
(2) .Net Business Connector Code:
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 Microsoft.Dynamics.BusinessConnectorNet; namespace GenerateQuote { public class SalesQuotation { // public string sUserName; //System.Net.NetworkCredential nc = new System.Net.NetworkCredential("karya-jovishp", "Pioneer1"); //System.Net.NetworkCredential nc = new System.Net.NetworkCredential("sa-grb13", "S3viceMet1mbeRs"); static string sRes; // Pass Quotation Id to sID // public static string sID;//= "QT-00167631"; //string strUserName = "karya-jovishp"; static string strUserName;//= "sa-grb13"; public string sAxConfig; // public static string sUserName; // public static string sPassword; public string sObjSer; public string connect(string sUserName,string sPassword,string sID) { System.Net.NetworkCredential nc = new System.Net.NetworkCredential(sUserName, sPassword); Axapta ax; //strUserName = "karya-jovishp"; strUserName = sUserName;//"sa-grb13"; ax = new Axapta(); bool b; try { // Login to Microsoft Dynamics Ax. ax = new Axapta(); ax.LogonAs(strUserName.Trim(), "", nc, "", "", "", ""); } catch (Exception e) { Console.WriteLine("Exception Caught :" + e); } // Logon was successful. try { // Call a static class method. sRes = ax.CallStaticClassMethod("pmf_GenerateQuotationRpt", "callBusinessLogic", sID).ToString(); } catch (Exception e) { Console.WriteLine("Exception Caught :" + e); b = ax.Logoff(); } // Display the returned string. return sRes; // Log off from Microsoft Dynamics AX. b = ax.Logoff(); } } }
Please let me know what m I doing wrong here.
Regards,
Mania