Calling Service Enabled Procedures from Visual Studio Tools and Dexterity

David Meego - Click for blog homepageWith the addition of Service Based Architecture (SBA) into Microsoft Dynamics GP 2015 and later, Dexterity global procedures can be marked as Service Enabled.

This allows a Dexterity global procedure to be a Service procedure which is exposed as a REST based web service via Service Base Architecture.

One benefit of writing code as a Service Procedure is that, in addition to being able to call the code as a web service, the code can also be called from other Dexterity applications and from Visual Studio Tools Addins (written using Visual Studio Tools for Microsoft Dynamics GP).

Note: Microsoft Dynamics GP must be running for both the Dexterity and Visual Studio Tools methods . If you wish to use Visual Studio without Microsoft Dynamics GP running, the only option is to use the Service Based Architecture REST web service calls. The web service call will spin up a Dexterity runtime instance and use a license while the service procedure is being executed.

For my examples, I will demonstrate calling the ServiceGetBatchList service procedure in the Batch Posting Service Toolkit product. But because I am too lazy to create new Dexterity and Visual Studio Tools projects, I will make the calls using GP Power Tools and its Runtime Execute and .Net Execute windows and also take advantage of the Parameter Lists feature.

Calling From Dexterity

From Dexterity, you can use the call with name in dictionary command to call the global procedure in another dictionary. The System.Collections .Net library has already been added to core Dynamics.dic, so it can be referenced with a using statement.

using System.Collections;
using System.Collections.Generic;

local List<System.String> BatchList = new List<System.String>();
local System.String Batch;
local text Results;

call with name "ServiceGetBatchList" in dictionary 7818, ""{%01%}, BatchList;

foreach Batch in BatchList do
	Results = Results + string(Batch) + char(13);
end foreach;
warning Results;

Where the Parameter List placeholder “”{%01%} is substituted for a valid Batch Source before the code is executed.

Calling From Visual Studio Tools

From Visual Studio Tools Addins, you can invoke the global procedure just by adding the appropriate references and using statements. You will need to add a reference to the Dictionary Assembly for the appropriate Dexterity product as well as a using statement.

For my example:

  • Reference: Application.PostingServices.dll
  • Code: using Microsoft.Dexterity.Applications.PostingServicesDictionary;

Now when I was writing the code using the .Net Execute window, I received the following errors.

Error CS0012: The type 'Microsoft.Dexterity.Svc.Foundation.IServiceProcedure' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Dexterity.Svc.Foundation, Version=16.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Error CS0012: The type 'Microsoft.Dexterity.Svc.Foundation.IRequestParser' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Dexterity.Svc.Foundation, Version=16.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Error CS0012: The type 'Microsoft.Dexterity.Svc.Foundation.IResponseBuilder' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Dexterity.Svc.Foundation, Version=16.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

The problem is that when calling a Dexterity global procedure that has the property of Service Enabled = TRUE, the system needs to reference the Microsoft.Dexterity.Svc.Foundation assembly. Adding this file as a reference solved the issue. Adding the using statement is optional.

  • Reference: Microsoft.Dexterity.Svc.Foundation.dll
  • Code: using Microsoft.Dexterity.Svc.Foundation;

Once this additional reference was added, the code would execute without issues. It appears that this extra step is required for a service enabled procedure.

using System;
using System.Windows.Forms;
using Microsoft.Dexterity.Bridge;
using Microsoft.Dexterity.Applications;
using Microsoft.Dexterity.Svc.Foundation;
using Microsoft.Dexterity.Applications.DynamicsDictionary;
using Microsoft.Dexterity.Applications.GpPowerToolsDictionary;
using Microsoft.Dexterity.Applications.PostingServicesDictionary;
using System.Collections;
using System.Collections.Generic;

namespace NetExecute
{
	public class Program
	{
		public void Run( )
		{
			// Add your code below this line

			List<System.String> BatchList = new List<System.String>();
			System.String Results = String.Empty;

			PostingServices.Procedures.ServiceGetBatchList.Invoke(
				""/*%01%*/, /* string Source */
				out BatchList /* out int BatchList - .Net Object */);

			foreach (System.String Batch in BatchList)
			{
				Results = Results + Batch + "\r\n";
			}
			MessageBox.Show(Results, "Batches");

			// Add your code above this line
		}
	}
}

Where the Parameter List placeholder “”/*%01%*/ is substituted for a valid Batch Source before the code is executed.

If you have both GP Power Tools and Batch Posting Service Toolkit, feel free to download the attached example code.

Hope this is helpful.

David

15-Jan-2018: Updated to clarify that Addins must be created using Visual Studio Tools for Microsoft Dynamics GP.

This article was originally posted on http://www.winthropdc.com/blog.

One thought on “Calling Service Enabled Procedures from Visual Studio Tools and Dexterity

Please post feedback or comments

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

WordPress.com Logo

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.