Tuesday, August 27, 2013
Create, Deploy, Troubleshoot and Consume external services in AX 2012 R2
Hi There!
I hope everyone is having a great week so far. Summer is almost over here in the US, and I feel like I haven't taken much advantage of it this year. The good thing, however, is that I have been able to really focus on service development lately, and a ton of other cool AX stuff.
On this post I would like to share with you how to Create, Deploy, Troubleshoot and consume an external service in AX 2012 R2. As we all know, this has changed dramatically from AX 2009 services. It used to be very easy to consume services in AX 2009 (you can see an example in my post Consume a Currency Exchange Rates Web Service from AX 2009 - WFC ).
In AX 2012 R2, however, this has become somewhat more involved. They are not necessarily harder to create and consume, but they require a few more steps to be setup. Now, the great advantage is that you can resolve the business logic either in the client itself (C# project) or in AX 2012 R2 (Server deployment). This comes handy for business that don't necessarily want to have an AX developer in house and/or large scale integration projects, among other reasons.
Let's get to it!
Open visual studio and create a new Class Library Project. Give it a name and click OK.
Right click the Project Name references folder and click the Add Service Reference button.
Paste the http://www.webservicex.net/genericbarcode.asmx?WSDL URL into the Address bar. This is a Barcode Generator service. Give it a name and click OK.
This will create a new Service Reference and a new AppConfig file where both the basic and custom bindings are automatically generated for you.
Right click the Project Name and choose Add "Service Name" to AOT. This will add the Csharp Project to the AOT under Visual Studio Projects/Csharp Projects.
Once the project has been added to the AOT, you can choose the following properties and deploy the service.
NOTE: If you choose to deploy to the server, you will need to enable Hot Swapping Assemblies on the server configuration file. See the following for more info (http://msdn.microsoft.com/en-us/library/gg889279.aspx). If you choose to do this, you will have to restart the AOS.
After it is deployed, you would add a code similar to the one below.
static void TestBarcodeGenService(Args _args)
{
Ed_SampleBarcodeGenerator.EdGenBarcode.BarCodeSoapClient service;
Ed_SampleBarcodeGenerator.EdGenBarcode.BarCodeData barCodeData;
System.Exception ex;
System.Type type;
;
try
{
service = new Ed_SampleBarcodeGenerator.EdGenBarcode.BarCodeSoapClient();
service.GenerateBarCode(barCodeData, "0000992882");
}
catch(Exception::CLRError)
{
ex = CLRInterop::getLastException();
info(CLRInterop::getAnyTypeForObject(ex.ToString()));
}
}
Well ... that's all for now folks. Stay tuned, there is going to be a huge load of useful information in the next few weeks.
Friday, August 23, 2013
Create a Transfer Journal using AX 2012 R2 Document Services and C#
Hi there,
On this post I would like to share some C# code to create a Transfer Journal using C#. I have written a few post in the past about services and they will help you understand how to create a service, service groups, deployment, etc.
Create Counting Journals
How to choose the right service
AX 2012 Services and AIF
Services Types
Creating a service in AX 2012
Back to the creation of a Transfer Journal with C#, this is an interesting code as we need to instantiate two different instances of the InventDim Table; InventDimIssue and InventDimReceipt.
InventDimIssue can be thought as the From values and InventDimReceipt can be thought as the To values (i.e. From Warehouse ==> To Warehouse).
In addition, another interesting point is that AX uses the InventJournalTable and InventJournalTrans for all the inventory journal entries, and we specified, in C#, which entity (AXD) will be using.
The following is the code:
private void InventTransferJourTest()
{
InventTransferJournal.CallContext callContext = new InventTransferJournal.CallContext();
InventTransferJournal.TransferJournalServiceClient servClient = new InventTransferJournal.TransferJournalServiceClient();
InventTransferJournal.AxdTransferJournal transjournal = new InventTransferJournal.AxdTransferJournal();
InventTransferJournal.AxdEntity_InventJournalTable journalheader = new InventTransferJournal.AxdEntity_InventJournalTable();
//Header
callContext.Company = "CEU";
journalheader.JournalNameId = "TransferJourId";
journalheader.Description = "Transfer Journal";
//End header
//Lines
InventTransferJournal.AxdEntity_InventJournalTrans journalLines = new InventTransferJournal.AxdEntity_InventJournalTrans();
journalLines.ItemId = "123456";
journalLines.Qty = 45;
journalLines.TransDate = DateTime.Now;
InventTransferJournal.AxdEntity_InventDimIssue inventDimIssue = new InventTransferJournal.AxdEntity_InventDimIssue();
inventDimIssue.InventBatchId = "RUT";
inventDimIssue.InventLocationId = "21";
inventDimIssue.InventSiteId = "1";
journalLines.InventDimIssue = new InventTransferJournal.AxdEntity_InventDimIssue[1] { inventDimIssue };
InventTransferJournal.AxdEntity_InventDimReceipt inventDimReceipt = new InventTransferJournal.AxdEntity_InventDimReceipt();
inventDimReceipt.InventSiteId = "2";
inventDimReceipt.InventLocationId = "11";
inventDimReceipt.InventBatchId = "RSR";
journalLines.InventDimReceipt = new InventTransferJournal.AxdEntity_InventDimReceipt[1] { inventDimReceipt };
//End Lines
journalheader.InventJournalTrans = new InventTransferJournal.AxdEntity_InventJournalTrans[1] { journalLines };
transjournal.InventJournalTable = new InventTransferJournal.AxdEntity_InventJournalTable[1] {journalheader};
try
{
servClient.create(callContext, transjournal);
}
catch (Exception e)
{
MessageBox.Show(e.InnerException.ToString());
}
}
That's all for today and stay tuned as in the next few weeks I will be talking about TFS and how to work with AX 2012 in a way that we utilize the TFS server to its max capacity.
Have a great weekend!
Thursday, August 22, 2013
Create Counting Journal in AX 2012 R2 using Document Services
Hi There,
It has been a long time since I created my last post. I have been very busy learning new things about AX 2012 R2 and other related technologies such as the Data Import/Export framework, TFS and AX 2012, SharePoint Development for the Enterprise Portal, among other. Everything will come in its own time and I'm planning in sharing a lot in the weeks to come, so stay tuned!
On this post I would like to share some C# code to create a Counting Journal in AX 2012 R2 using the InventCountingJournalService that ships with AX. Let's keep in mind that the AX 2012 R2 document services are a extremely low cost option of providing this features to an external client with no AX development whatsoever.
So, I would like to start from the beginning:
1- Create a Service Group
2- Add the InventCountingJournalService to the Service Group
3- Deploy the Service Group. This will output the following.
4- Get the WSDL URI from the inbound ports form.
5- Go to Visual Studio, create a new windows form project, add a button and double click the button to create a button event.
6- Right - Click the Service References and choose Add Service Reference.
7 - Past the WSDL URI and click GO
8- Give your service a name i.e. InventCountingJournnal
9 - Write the following code and test.
private void InventCountingJournal()
{
InventCountingJournal.CallContext callContext = new InventCountingJournal.CallContext();
InventCountingJournal.CountingJournalServiceClient servClient = new InventCountingJournal.CountingJournalServiceClient();
InventCountingJournal.AxdCountingJournal countJournal = new InventCountingJournal.AxdCountingJournal();
InventCountingJournal.AxdEntity_InventJournalTable journalHeader = new InventCountingJournal.AxdEntity_InventJournalTable();
//Header
callContext.Company = "CEU";
journalHeader.JournalNameId = "CountJour";
journalHeader.Description = "Counting Journal";
//Header
//lines
InventCountingJournal.AxdEntity_InventJournalTrans journalLines = new InventCountingJournal.AxdEntity_InventJournalTrans();
journalLines.ItemId = "12345";
journalLines.Qty = 50;
journalLines.TransDate = DateTime.Now;
InventCountingJournal.AxdEntity_InventDim inventDim = new InventCountingJournal.AxdEntity_InventDim();
inventDim.InventBatchId = "3";
inventDim.InventLocationId = "1";
inventDim.InventSiteId = "3";
journalLines.InventDim = new InventCountingJournal.AxdEntity_InventDim[1] { inventDim };
//Lines
journalHeader.InventJournalTrans = new InventCountingJournal.AxdEntity_InventJournalTrans[1] { journalLines };
countJournal.InventJournalTable = new InventCountingJournal.AxdEntity_InventJournalTable[1] { journalHeader };
servClient.create(callContext, countJournal);
}
You can test this by clicking the button, and calling this method. A new counting journal would be created in AX. Then, you can either have a batch posting all the journals or simply have a user doing it manually.
That's all for now!
Subscribe to:
Posts (Atom)