Skip to main content

Dynamics NAV: How To Consume An External SOAP Web Service With .Net/Dotnet Interop

The reason for this blog post is that I needed to consume a web service from a partner company that give customer specific details. So far I haven’t worked with consuming web services in NAV so for me this is very new. This post is about the trial and errors that I had on the way implenting this in NAV 2015 on a Windows Server 2012 machine. My main objective was to solve this with dotnet interop.


I started with googling it but for the most part I ended up with information about how to publish a web service from Dynamics NAV but I want to consume.

After a while I realised there are a couple of ways of doing this.

  1. Use automation object (which I don’t want to do)
  2. Create a dotnet wrapper and handle it as an addin (my Visual Studio skills aren’t the best)
  3. Use dotnet interop in NAV (Yes!)

Eventually I found this post which seemed like it was exactly what I was looking but with only one problem. He was using the following dotnet librarys which I didn’t have  on the target machine 

DotNetXmlHttp DotNet MSXML.XMLHTTPRequestClass.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

DotNetXmlDoc DotNet MSXML.DOMDocumentClass.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

DotNetXmlNodeList DotNet MSXML.IXMLDOMNodeList.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

DotNetXmlNode DotNet MSXML.IXMLDOMNode.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

I found MSXML 6.0 installer but after installing it I never found the dotnet libraries and that led me to this mibuso post that had the same problem.
There another user mentioned that:

The use of MSXML is not supported in .NET applications.Microsoft does not support the use of MSXML (Microsoft’s COM-based XML parser) in .NET applications.

Which is stated here. The page also say that:

Support for implementing standards-based XML functionality in .NET applications is built into the .NET Framework. The .NET Framework classes in the System.xml namespaces should be used to implement standards-based XML functionality in .NET applications.

Crap! Either I go with the “ugly” hack to deploy the microsoft.msxml.dll to the addins folder like the mibuso post or I try to find another example that uses pure dotnet interop. With a help from a colleague I found this example which actually did work! ðŸ˜€

I’m going to use that example and apply it to my scenario but since the web service is a paid service I’m going to show a less and fake version of it but still the details are accurate.

In order to build this web service we have to look at which ingredients we already have.

  • Dynamics NAV dotnet example code
  • SOAP web service adress (with user login and password)

What we are missing is the XML layout of the web service request and response. There is a tool called SOAP UI which is excellent for this scenario and it is FREE! Download and install it. One started choose New SOAP Project. Fill in the project name, the web service WSDL adress.

soapui-connecttosoap

After that choose Request1 and you will see that it has created template XML code to use when calling the service.
soapui-faketemplaterequest

If you replace the questionmark with actual values and press play you will be given the actual response. In this case I have created an anonmous fake response.
soapui-fakerequestresponse

Ok, now we have everything. Lets start with building the code.

GlobalVariableDeclaration.JPG

Put our request XML text into a stringbuilder variable.
xmlrequest

Create the call code with the URL. Note that you leave the ?wsdl out of the adress in the url and the SOAPAction should only contain the page name and also without the ?wsdl.
adressdeclaration

At the end of the code we will copy the XML response into a XML document which we saves to disk to later analyse how to use the XML data.
End of function

And that was that! To extract data from the request XML is another topic.

Comments

Popular posts from this blog

AL Development 03 - How to Develop New Report in AL?

Hi Readers, Now its time to develop the most important part of Navision which client desire the most yes you are correct i am talking about Reports. As we know to develop any solution in Business Central we must start working on AL Code Extension so from this blog you will get to know the detailed step how to create a Report through AL Code in business Central. Note: As of now there is no provision to customise the base report. Let’s try to create a simple report. Add new file with .al extension in your project folder through visual studio code My File Name is My_report.al  Code Snippet for adding a new Report, use snippet treport as shown below: Next Step to set these Report Properties - • Assign ID and Provide a name of the Report that you are adding. • Set UsageCategory to ReportsAndAnalysis. • Set ApplicationArea to All. As you select the treport snippet then a default structure of the report is created as below: Basically, there are 3...

Custom sheet name in RDLC Reports

Hi Readers, In this article we are going to discuss how to change the excel sheet name while using base Navision SAVEASEXCEL functionality. Applicable for RDLC reports of Navision and SSRS reports. Let’s say we have the following report that shows total sales by product category by territory:   When we export this report to Excel, we’d like each territory to appear in its own worksheet and each worksheet named after its territory: How do we make this work? Easy! 1) Put every group on its own page. 2) name each page using the same field the group uses. Step 1: Put each group on its own page To put each group on its own page, open the group’s property window. Then, in the Page Breaks category, put a check mark in the Between each instance of a group check box. Click OK to complete this step. Step 2: Name the pages of the group With the group selected in the Row Group s panel, press F4 to open the Properties window. Next, expand the Group ...

AL Development 01 - How to Develop New Table in Database?

Hello readers, As we know to develop any solution in Business Central we must start working on AL Code Extension so from this blog you will get to know the detailed step how to create a table through AL Code in business Central. Requirement : Need to create a new table with below fields: Now let’s Start: Try to keep a naming standard for your projects; As I am using the combination of Table description +Table-ID, you can use your own naming convention. So, my table file name is: My_Table50129.al AL provides a list of the snippets to make it easy for developers to add objects in extension. Snippet for getting a table layout use snippet ttable (here we have to t as prefix for every type of object we want to create in AL) as shown below: Now Assign the ID and name of the table as below: As you select the ttable from the list a default table design structure is created as shown below: You can divide the whole table into 4 Sections - · F...