Microsoft Dynamics Nav: Using an XMLPort as a .NET DataSource

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.

Microsoft Dynamics Nav: Using an XMLPort as a .NET DataSource

This example slightly expands on the previous example and uses the Customer XMLPort as the datasource.

  1. Ensure that the MaxOccurance property is set for the Text element Open_Balance.
    XMLPort Designer
  2. Create a CodeUnit with a Function that uses the XMLPort as a parameter. Ensure that the parameter is marked as a Var parameter.
    CodeUnit Function
  3. Publish the CodeUnit as a Web Service from within Microsoft Dynamics Nav and restart the “Microsoft Dynamics Nav Web Services” service.
    Microsoft Dynamics Nav Web Service
  4. Create a new .NET Application and add the Web Reference for the CustomerExport CodeUnit published as a Web Service
  5. Place a DataGridView on the form
  6. 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();
                ws.ExportCustomer(ref 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<<<.

Pingbacks and trackbacks (2)+

Add comment

Reading Stuff

Information in this document subject to change without notice.
All Software source code published is for demonstration and knowledge sharing purposes only. The Code is supplied "as is" without warranty as to result, performance or merchantability. Use at your own risk.
The opinions expressed herein are the opinions of the author and do not reflect those of any other entity.