I am trying to get Epicor 10.1.400.18 to retrieve a new quote number from an external application. When I run this code in the external application, the GetNewQuoteHed method fails with this error:
Application Error
Exception caught in: Erp.Adapters.Quote
Error Detail
Message: Unable to cast object of type ‘Ice.Core.Session’ to type ‘Ice.Lib.Framework.ILaunch’.
Program: Erp.Adapters.Quote.dll
Method: get_quoteData
Client Stack Trace
at Erp.Adapters.QuoteAdapter.get_quoteData()
at Erp.Adapters.QuoteAdapter.GetNewQuoteHed()
The code is:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim QNUM As Integer = 0
Dim CustID As String = “2305”
Dim epiSession = New Ice.Core.Session(“Manager”, “manager”, “”, Ice.Core.Session.LicenseType.Default, “C:\Epicor10\Client\config\ERP10.1.sysconfig”, False, “DTSF”, “MfgSys”)
Dim custBO As Erp.Adapters.QuoteAdapter = New Erp.Adapters.QuoteAdapter(epiSession)
If custBO.BOConnect() Then
Dim gotHead As Boolean
gotHead = custBO.GetNewQuoteHed()
If gotHead = True Then
custBO.QuoteData.QuoteHed.Rows(0)(“CustomerCustID”) = CustID
custBO.GetCustomerInfo()
custBO.Update()
QNUM = custBO.QuoteData.QuoteHed.Rows(0)(“QuoteNum”)
Else
MsgBox(“Could not retrieve new Quote Head”)
End If
Else
MsgBox(“Could not connect to BO”)
End If
TextBox1.Text = "QuoteNumber = " & QNUM.ToString()
End Sub
End Class
I would follow this post, while not the same it will provide the insight to be able to fix the issue. @josecgomez has a couple good points in this post around WCF or Rest.
using (Session = new Ice.Core.Session("user", "pass", Session.LicenseType.GlobalUser, @"C:\Epicor\ERP10.1Client\Client\config\E10LiveDB2.sysconfig"))
{
ILauncher oTrans = new ILauncher(epiSession);
//Do Epicor stuff here
//Use the ILauncher like oTrans --- JobAsmSearchAdapter joa = new JobAsmSearchAdapter(oTrans);
}
``
For you it may be something like oTrans as ILauncher = new ILauncher(epiSession)
Class is found in Ice.Framework fyi
These suggestions will work… however keep in mind Dll dependency and having to pass in the config file, plus consuming those licenses (make sure you are releasing them at the end etc…)
Most of these issues are avoided if you use the web services or REST. (As the examples provided before) Since you are having to tinker with it anyways I highly recommend you use the web services or REST and save yourself some headaches.
This worked. Thanks Chris! For anyone else, here is the code in Visual Basic:
These are the references I added:
Erp.Contracts.Bo.Quote.dll
Ice.Lib.EpiClientLib.dll
Erp.UI.QuoteEntry.dll
Erp.Adapters.Quote.dll
Ice.Core.Session
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim QNUM As Integer = 0
Dim CustID As String = "2305"
Dim epiSession = New Ice.Core.Session("userID", "pwd", "", Ice.Core.Session.LicenseType.Default, "C:\Epicor10\Client\config\ERP10.1.sysconfig", False, "cmpny", "plant")
Dim oTrans As Ice.Lib.Framework.ILauncher = New Ice.Lib.Framework.ILauncher(epiSession)
Dim custBO As Erp.Adapters.QuoteAdapter = New Erp.Adapters.QuoteAdapter(oTrans)
If custBO.BOConnect() Then
Dim gotHead As Boolean
gotHead = custBO.GetNewQuoteHed()
If gotHead = True Then
custBO.QuoteData.QuoteHed.Rows(0)("CustomerCustID") = CustID
custBO.GetCustomerInfo()
custBO.Update()
QNUM = custBO.QuoteData.QuoteHed.Rows(0)("QuoteNum")
Else
MsgBox("Could not retrieve new Quote Head")
End If
Else
MsgBox("Could not connect to BO")
End If
TextBox1.Text = "QuoteNumber = " & QNUM.ToString()
TextBox1.Update()
End Sub
End Class
Does WCF work in 10.1.400.18? Does REST? WCF looks like there is a lot of setup involved. We will investigate further. I value your input. If you had to choose, which one would you use in 10.1.400.18 and beyond?
WCF works on any version of 10, I would go with WCF if REST isn’t available. There is a WCF How To Guide in Epic Web that walks you through how to implement it as well as examples in the posts outlined above.
But, for the record… there isn’t anything wrong with the example that you and @Chris_Conn are working on, as a matter of Fact the adapters are nothing but implementations of the WCF Proxies. The only downside as I stated is that you create version dependency because you are using the DLL’s and the possibility of having rouge Session if you don’t dispose them properly.
The trade off is maintenance down the road being more difficult or putting a bit of effort now to have easier time upgrading in the future