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

25 Feb

EDIT 2018-12-04: Have added the last missing part to this post.
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=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

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

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

DotNetXmlNode DotNet MSXML.IXMLDOMNode.’Microsoft.MSXML, Version=, 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.


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

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.

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


Put our request XML text into a stringbuilder variable.

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.

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.





Posted by on 2017-02-25 in Okategoriserade


Tags: , , , , , , ,

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

  1. ctrlshiftf4

    2017-12-20 at 04:30

    Is this the complete code? Where have you saved the xml into even a text?


  2. Rakesh Budarapu

    2018-08-10 at 11:01

    Good afternoon from Dubai UAE.
    Kindly guide us on the remaining part of the blog on how to get a response and save it Navision.
    Thanks in advance


    • Capone

      2018-12-05 at 11:59

      Sorry for the late adjustment 😦 Haven’t been blogging for a while



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

The BC Docs Librarian

Tips and news for AL programmers

Stefan Maroń

Dynamics 365 Business Central

James Pearson

Thoughts about Dynamics 365 Business Central, Git, Azure DevOps, PowerShell, Automated Testing, Visual Studio Code...and maybe some other stuff

Roberto Stefanetti BLOG

MVP & MCT Microsoft Dynamics 365 Business Central, Powershell, Azure, SQL Server


DevOps starts with culture!

Comments for DevOps ABCs Blog

Reflections from the ERP field

DevOps ABCs Blog

Reflections from the ERP field

Dynamics 365 Business Central for Partners

Reflections from the ERP field

Freddys blog

Learn something new... - then Teach someone!

Stefano Demiliani Technical Blog

Reflections from the ERP field

David Worthington's NAV Performance Blog

Micosoft Dynamics NAV Performance Testing & Optimization

Freddys Blog

Reflections from the ERP field

Marije Brummel Blog | Business Central, Azure and more...

Design Patterns, Performance, Clean Code

Ideas in the cloud

Goprowe AB

Reflections from the ERP field


Reflections from the ERP field

The NAV Viking´s Blog

- Sharing my experience in the Dynamics NAV world

Comments for

Reflections from the ERP field

Nav Can Be Fun

Its Really Fun to Work with Microsoft Dynamics Nav / D365 Business Central

%d bloggers like this: