Last summer, when I posted my first article, I thought blogging would be easy and I’d post every week. Actually, it’s not that easy! After a few months, here’s the article I promised: a 100% generic web service client for NAV.

I wanted to automate all my web service calls without managing, deploying, and struggling with all the DLLs generated by Visual Studio. I hoped to use CU 1290 SOAP Web Service Request Mgt. as described here, but quickly noticed it doesn’t work if the web service comes from another NAV Database (due to the SOAP version used natively by NAV). So, I started looking into how Visual Studio generates DLLs. I found the answer in this excellent MSDN article.

This intro is getting long—let’s get to the point!

I translated the MSDN article’s approach using .NET interoperability in NAV. The result was astonishing. Check out the similarities:

Pure C# Pure C# Pure C/AL Pure C/AL

The C/AL code reminds me of this great article by Vjekoslav Babić. My first reaction: What the he**, I’m writing code like the great Vjekoslav Babić!

How It Works

The codeunit uses four main functions:

  1. InitClient: Compiles the WSDL on the fly and prepares a ready-to-use client (proxy, DLL, etc.) in memory.
  2. InitCallMethod: Prepares the method to call with its parameters.
  3. CallMethod: Invokes the method and retrieves the web service result.
  4. GetObjectValue: Uses the web service result however you want (simple text, decimal, or complex record).

Example Usage

How to use

and this is the result:

Example

You can download the full code here: gws-with-examples.

Some readers may say:

But this needs to compile the client every time; this is huge for the memory

This is true. The answer will be the subject of one of my next posts.


Additional Resources


Have questions or suggestions? Feel free to reach out via LinkedIn or Twitter.