I previously discussed connecting to Microsoft Dynamics Nav using a Web Service and also discussed using an XMLPort to create an XML file. Building upon these concepts we can use a Microsoft Dynamics Nav XMLPort as a DataSource for a .NET application. I recommend reading the previous posts before continuing with this one.
This example slightly expands on the previous example and uses the Customer XMLPort as the datasource.
- Ensure that the MaxOccurance property is set for the Text element Open_Balance.
- Create a CodeUnit with a Function that uses the XMLPort as a parameter. Ensure that the parameter is marked as a Var parameter.
- Publish the CodeUnit as a Web Service from within Microsoft Dynamics Nav and restart the “Microsoft Dynamics Nav Web Services” service.
- Create a new .NET Application and add the Web Reference for the CustomerExport CodeUnit published as a Web Service
- Place a DataGridView on the form
- Set the DataSource for the DataGridView to be the Microsoft Dynamics Nav XMLPort
private void Form1_Load(object sender, EventArgs e)
CustomerExport_Binding ws = new CustomerExport_Binding();
ws.UseDefaultCredentials = true;
ws.Url = "http://localhost:7047/DynamicsNAV/WS/CRONUS%20USA,%20Inc./Codeunit/CustomerExport";
Customers customers = new Customers();
BindingSource bs = new BindingSource();
dataGridView1.DataSource = bs;
bs.DataSource = customers.Customer;
A Microsoft Dynamics Nav XMLPort can easily also be the datasource for a DataGrid in an ASP.NET application.
The sample application referenced in this post can be downloaded >>>here<<<.