All Products
Search
Document Center

Prepare the .NET SDK environment

Last Updated: Sep 13, 2019

Complete the following preparations before accessing MQ through .NET SDK.

Note:

  • The topic and group ID in the code must have been created in the MQ console first. The message tag can be specified by the application users. For more information about the creation process, see Step 2: Create resources in Quick start for primary accounts.

  • Applications that use MQ must be deployed on Alibaba Cloud ECS instances.

Download SDK

Windows .NET SDK

The .NET SDK we provide is based on the managed wrapper of MQ C++. In this way, the .NET SDK is independent of Windows .NET SDK public libraries. C++ multi-thread concurrent processing is used to ensure the efficiency and stability of the .NET SDK.

When Visual Studio is used to develop .NET applications and class libraries, the default target platform is “Any CPU”, that is, X86 or X64 is automatically selected according to the CPU type when the application runs. When running, CLR transmits its JIT as the machine code X86 or X64. The C or C++ compiled DLL is the machine code. Accordingly, the policies of the platform are determined when the application is compiled. When the compilation options are set, the C/C++ project is compiled as an X64 64-bit DLL. Therefore, the 64-bit DLL in release mode compiled using Visual Studio 2015 is provided. Other Visual Studio versions also can be used.

Download earlier versions of Windows .NET SDK

Note:

  • The SDK based on the managed wrapper has a lot of problems, and cannot normally operate on ASP.NET. Therefore, a new version SDK was released on December 29, 2016.
  • The new SDK calls underlying DLLs based on C# PInvoke and uses the open-source software SWIG to generate the PInvoke wrapped code. Compared with the managed SDK, the new SDK is more stable and easier to deploy and install.
  • The managed SDK is no longer maintained. Only the latest stable version is provided.

We recommend that both new users and old users download the new SDK.

For the URL to download the latest .NET SDK, see Release Notes.

Download and decompress the .rar package of the .NET SDK. The .rar package contains the following directories and files:

  • example/
  • lib/
  • demo/
  • interface/
  • SDK_GUIDE.pdf
  • changelog

The preceding directories and files serve the following purposes:

  • example: This folder contains examples for sending and consuming normal messages and ordered messages, and examples for sending messages in one-way mode.

  • lib: This folder contains the C++ DLL files and the runtime installation package for Virtual C++ 2015.

  1. 64/
  2. NSClient4CPP.lib
  3. ONSClient4CPP.dll
  4. ONSClient4CPP.pdb
  5. vc_redist.x64.exe
  • SDK_GUIDE.pdf: This file describes how to prepare the SDK environment and contains FAQ.

  • changelog: This file lists the problems that have been fixed and the new features of the new version.

  • interface: This folder contains codes that are called to wrap PInvoke, which needs to be used in the user project code.

.NET SDK configuration

Configuration for using .NET SDK in Visual Studio 2015

  1. Use Visual Studio 2015 to create your project.

    net1

  2. Right-click the project and choose Add > Existing Itemto add all the files in the interface folder in the downloaded SDK package.

    net2

  3. Right-click the project and choose Properties > Configuration Manager. Set Active Solution Configuration to Release, and Active Solution Platform to x64.

  4. Write a test program and compile it. Move the DLL in the SDK to the same directory of the executable files or to the system directory. Then, the DLL can be executed.

    .netenvir

Note:

The SDK provides a demo that has been set up, and you can open the project and compile it. When running the SDK, copy the DLL files to the same directory of the executable files, as shown in the following figure:

.netenvir2

Configuration for using MQ SDK to create ASP.NET in Visual Studio 2015

  1. Create an ASP.NET Web Forms project by using Visual Studio 2015.

    aspnet_1

  2. Right-click the project and choose Properties > Configuration Manager. Set Active Solution Configuration to Release, and Active Solution Platform to x64.

    aspnet_2

  3. Right-click the project and choose Add > Existing Item to add all the files in the interface folder in the downloaded SDK package.

See the preceding step 2 for configuring the normal .NET project.

  1. In the file Global.asax.cs, add the codes for enabling and disabling the SDK.

Note:

We recommend that you wrap the SDK code to a singleton class, to prevent the SDK code from being collected by the garbage collector due to scope issues. The folder example in the SDK provides Example.cs, which implements a simple singleton. To use Example.cs, you need to include Example.cs in your project.

  1. ```csharp

sing System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Optimization;using System.Web.Routing;using System.Web.Security;using System.Web.SessionState;using ons; //It is the namespace where the SDK resides.using test; // It is the namespace where a wrapped SDK class resides. For more information, see Example.cs in the folder example in the SDK.namespace WebApplication4{public class Global : HttpApplication{void Application_Start(object sender, EventArgs e){// Code that runs on application startupRouteConfig.RegisterRoutes(RouteTable.Routes);BundleConfig.RegisterBundles(BundleTable.Bundles);try{// The code for starting the SDK. The following is a code after the SDK is wrapped into a simple singleton.OnscSharp.CreateProducer();OnscSharp.StartProducer();}catch (Exception ex){//Handle exceptions.}}protected void Application_End(object sender, EventArgs e){try{// The code for disabling the SDK.OnscSharp.ShutdownProducer();}catch (Exception ex){// Handle exceptions.}}}}```

  1. Write a test program and compile it.

  2. Move the DLL in the SDK to the same directory of the executable files or to the system directory. Then, the DLL can be executed.

DLL deployment

  1. Choose Tools > Options > Projects and Solutions > Web Projects. On the page that is displayed, select Use the 64 bit version of IIS Express for web sites and projects .

iis_1

iis_2