(For more resources related to this topic, see here.)
There are a number of web services that have already been created and deployed with the standard Dynamics AX install. There are a lot more services that you can publish as web services through the AOT in just a matter of minutes, allowing you to access and update almost any area of Dynamics AX from other applications.
In this recipe, we will show you how you can create new web services from within the Dynamics AX development environment.
To create a new web service within Dynamics AX, follow these steps:
You can continue adding as many services into your service group as you like.
To see the web service that was created, open the Inbound ports option from the Services and Application Integration Framework folder of the Setup group in the System administration area page.
Your new service should show up there. If you look at the WSDL URI: field for the inbound port, you will find the URL for the web service itself.
If you browse to that location, you will see the schema for the web service that you will use for other applications to call, in order to update Dynamics AX. For us it’s not that user-friendly, but for applications, this is all they need to know.
The web services that Dynamics AX creates seem to work best for programming interfaces, and sometimes programs have problems with the format of the web service call. InfoPath is one of these programs. So, we need to wrap the Dynamics AX service within a web service wrapper that InfoPath is able to use. This is not as complicated as it sounds though, and you can quickly do this with Visual Studio.
In this recipe, we will show how you can create a web service wrapper through Microsoft Visual Studio that we can use from within InfoPath.
In order to do this you need to have a copy of Visual Studio. We will be using Visual Studio 2010 in our example, but you should be able to create similar web service wrappers using earlier versions as well.
To create a web service wrapper, follow these steps:
When you return to your web service project, you will be able to see the web service reference in the Service References group within Solution Explorer .
using AXSalesOrderService.SalesOrderServiceReference;
[WebMethod] public string NewSalesOrder( string company, string language, string custAccount, string PONumber, string itemID, decimal salesQty, string salesUnit ) { SalesOrderServiceClient client = new SalesOrderServiceClient(); AxdSalesOrder salesOrder = new AxdSalesOrder(); AxdEntity_SalesTable salesTable = new AxdEntity_SalesTable(); AxdEntity_SalesLine salesLine = new AxdEntity_SalesLine(); CallContext callContext = new CallContext(); EntityKey[] keys; EntityKey key; KeyField fld; salesTable.CustAccount = custAccount; salesTable.ReceiptDateRequested = new DateTime(2013, 03, 20); salesLine.ItemId = itemID; salesLine.SalesQty = salesQty; salesLine.SalesUnit = salesUnit; salesTable.SalesLine = new AxdEntity_SalesLine[] { salesLine }; salesTable.PurchOrderFormNum = PONumber; salesTable.SalesType = AxdEnum_SalesType.Sales; salesOrder.SalesTable = new AxdEntity_SalesTable[] { salesTable }; callContext.Company = company; callContext.Language = language; keys = client.create(callContext, salesOrder); key = keys[0]; fld = key.KeyData[0]; return fld.ToString(); }
You can see this in the following screenshot:
When you compile your program and run it, you will be taken to the web interface for the new web service showing all of the methods that you’ve exposed.
If you click on the NewSalesOrder web service call, you will be able to see all the parameters that are required to perform the web service.
You can test your web service by filling in the parameters and then clicking on Invoke . This will perform the web service and return with the results of the call.
With a little bit of extra code, you can have the web service return back the order number as well.
To double-check if that everything worked, you can open up Dynamics AX and you should be able to see the new sales order.
I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…
Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…
Once we learn how to deploy an Ubuntu server, how to manage users, and how…
Key-takeaways: Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…
While developing a web application, or setting dynamic pages and meta tags we need to deal with…
Software architecture is one of the most discussed topics in the software industry today, and…