.NET

Transaction Integrity with Connected Systems

by Vjekoslav Babic on March 5, 2013

Broken pencilWith .NET Interoperability around, it’s very likely you’ll be synchronously calling external web services from C/AL, to exchange data. I won’t go into discussing whether or not this kind of architecture is good (my own position is that it isn’t), you may end up having situations where your C/AL code simply makes a synchronous call to external systems, such as web services.

Any external call is an expected point of failure. An important question you must always have in mind when calling external functions is transaction integrity. When writing code that targets only NAV, the structure of code is largely irrelevant, as long as you are not using COMMITs (which is another thing you should avoid at all costs). However, as soon as you introduce external calls, the structure becomes critically relevant. Critically relevant.

I’ve talked about this during my 2012 NAV TechDays session, and I promised I’d blog about it – so, here it goes.

[click to continue reading…]

{ 3 comments }

Cross-Call State Sharing in Web Services

by Vjekoslav Babic on February 21, 2013

imageWeb services in NAV have an interesting feature: they are stateless. For a system which is pretty stateful otherwise, this feature can be outright annoying. You must get used to it, and then make sure you never ever write code as if there was any state preserved on the other end.

The reason for this is simple – there is no actual protocol that you use to communicate with NAV through SOAP. Calls are ad-hoc, essentially atomic, each one can accomplish a great deal of things in a single go, and it makes programming a whole lot simpler. The price you pay is the state. Once you close the connection, the session ends and the transaction commits (or rolls back). Next call starts from scratch.

If you need to preserve any state between the calls, whatever that state might be, you are toast. NAV simply doesn’t support it out of the box. A common misconception is that single-instance codeunits help. They don’t. The single instance is always single per session, and since each call is an isolated session, it means that each single instance codeunit dies at the end of the call.

Pretty annoying, isn’t it?

Well, it is, and it isn’t. I won’t argue about validity of situations where you need to preserve state across multiple web services calls – I am going to show you how to do it when you need it.

And what I’m going to show you works in both NAV 2009 R2 and 2013.

[click to continue reading…]

{ 8 comments }

Generics in .NET Interop for NAV 2013

by Vjekoslav Babic on May 17, 2012

image.NET Framework is full of programming conceptual gems, that are now at the fingertips of us poor C/AL folks. One of those is generics. However, the C/AL support for generics at the first glance seems rather limited, and the help file says that you can’t specify data types, and that all generics will be instantiated with System.Object as their type.

However, with Microsoft Dynamics NAV 2013, there is a very simple way which allows you to use generics with other data types, as well. So, if .NET Framework Interoperability interests you a slightest bit, here’s a solution.

The example below will be for the System.Collections.Generic.Dictionary<,>, and I will show how to use instances of the Dictionary<,> object with any desired data type, without having to pull in any external assemblies.

[click to continue reading…]

{ 1 comment }

Passing strongly-typed data to Web services

by Vjekoslav Babic on February 22, 2012

imagePassing strongly-typed data to NAV Web services can be trickier than it seems. If you are lucky, you can make your method accept strongly-typed parameters, and you are good to go. However, if you just can’t avoid sending text data, your text must be encoded in EN-US format, otherwise it will cause problems (see this).

What the heck, just encode the data as EN-US, right? Not quite. There are a myriad of reasons why data can come in non-EN-US encoding, one of which is this: it’s the Web services, for Pete’s sake – anyone or anything can call them.

[click to continue reading…]

{ 4 comments }

Web Reference vs. Service Reference, Part 3

by Vjekoslav Babic on January 31, 2012

Al Pacino in "Devil's Advocate"Fasten your seatbelts, you are in for the next round of Web Reference vs. Service Reference, which brings an unexpected twist to the story. After giving reasons why not to use Web References, I’ll now put my devil’s advocate’s hat on, and try to have you change your mind.

It’s simple: there are situations where Service Reference won’t work as expected, and Web Service will.

[click to continue reading…]

{ 1 comment }

Web Reference vs. Service Reference, Part 2

January 30, 2012

A beauty of Web services is that they don’t need to care at all about who’s consuming them. Whether there is .NET on Windows, Java on Linux or some proprietary stuff on an iPad on the other end, they do exactly the same stuff. To make it short: if something works on one platform and [...]

[click to continue reading…]

Web Reference vs. Service Reference, Part 1

January 27, 2012

Once upon a time, Freddy has delivered a great series on connecting to NAV Web Services from a smorgasbord of technology flavors. If you are a .NET enthusiast, like me, the obvious choice is to connect through the tools that are at your disposal in Visual Studio: the proxy classes. A proxy class is a [...]

[click to continue reading…]

The Beauty and The Beast: NAV and .NET

September 30, 2011

If there wasn’t one already, someone should have invented Belgium. There are two things in this world that I love, and probably shouldn’t (and an oversized red speaker’s shirt I got from Luc today did a darned god job at concealing the unlucky consequences of overly indulging in both of them): beer and chocolate. Boy, [...]

[click to continue reading…]

NAV TechDays 2011 in Antwerp, Belgium

June 19, 2011

If you are a follower of Mibuso.com you may already know that they are organizing NAV TechDays in Antwerp, Belgium, on September 29 and 30, a conference dedicated to all NAV developers, solution architects and technical folks in general. The content will be strictly technical, and speaker list includes a lot of Who’s Who of [...]

[click to continue reading…]

Microsoft Dynamics NAV 2009 R2 ships

December 15, 2010

I’m growing increasingly impatient as the progress bar on my File Transfer Manager is approaching 100%. Behind the cryptical download title—Dynamics.NAV60R2.HR.1097366.DVD.zip—hides the much awaited Microsoft Dynamics 2009 R2 HR (Croatian) release of Microsoft Dynamics NAV. Yes, Microsoft Dynamics NAV 2009 has officially shipped, and you can download your copy at Microsoft Dynamics NAV 2009 R2 [...]

[click to continue reading…]

Death of Classic (C/SIDE) Client

October 28, 2010

Yesterday, during a coffee break at the What’s New in Microsoft Dynamics NAV 2009 Technical for Application Consultants training in Vilnius, Lithuania (a fabulous place, by the way), a discussion arose around the destiny of the Classic (or C/SIDE) client in NAV. Some participants stated that “it’s never going to go away” because “Microsoft would [...]

[click to continue reading…]