edit-icon download-icon

.NET SDK preparation

Last Updated: Oct 16, 2018

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

Note:

  • The topic, producer ID, and consumer ID used in the code need to be created on MQ console first. Message tag can be completely customized by the application. For detailed creation process, see Step 2: Create resources in Quick start guide.

  • Applications using MQ services need to be deployed on Alibaba Cloud ECS.

Download SDK

Windows .NET version:

The .NET version we provided is based on the managed wrapper of MQ CPP version, which ensures that .NET is independent of Windows .NET public libraries. C++ multi-thread concurrent processing is adopted to ensure the efficiency and stability of the .NET version.

When VS is used to develop .NET applications and class libraries, the default target platform is “Any CPU”, that is, X86 or X64 can be automatically selected according to the CPU type during runtime. During operation, CLR will transmit its JIT as X86 or X64 machine code. While C or C++ compiled DLL is the machine code. Accordingly, the policies of its platform are determined during the compilation. C/C++ projects are compiled into X64 64-bit dll by configuring compilation settings, so we provide the 64-bit version dll including VS2015 compiled release. Other VS versions are also supported.

Download old version Windows .NET SDK

Note:

  • SDK based on the managed wrapper has a lot of problems, and cannot run stably on ASP.NET, so a new version SDK was released on 2016/12/29.
  • The new version SDK invokes underlying dll based on C# PINVOKE, and generates PINVOKE wrapped code using open source software SWIG. As compared with the managed version SDK, the new version SDK is more stable, and easier to deploy and install.
  • The managed version of the SDK will not be maintained, and only the latest stable version will be provided.

New users or older users who do not care for updating cost can download the new version SDK.

Download the New Version Windows .NET SDK

Decompress the package, and the following directories will be created:

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

The roles of the directories and files are as follows:

  • example: Include examples of sending standard messages, Oneway messages, ordered messages, consumption of standard messages and ordered messages.

  • lib: Underlying C++ DLL and related files, and the runtime environment install package for Virtual C++ 2015.

    1. 64/
    2. NSClient4CPP.lib
    3. ONSClient4CPP.dll
    4. ONSClient4CPP.pdb
    5. vc_redist.x64.exe
  • SDK_GUIDE.pdf: Document and FAQ for SDK environment preparation.

  • changelog: A list of solved problems and new features in the new version.

  • interface: Invoked code for wrapping PINVIK, which needs to be included 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 select Add > Existing Item, and add all files in the interface folder in the downloaded SDK.

    net2

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

  4. Write a test program and compile it, and move the dll in the SDK to the same directory as the executable files, or to the system directory for execution.

    net3

    Note:

    The SDK provides a demo that has been set up, and you can open the project and compile it. Copy the related dll files to the same directory as the executable files during the execution, as shown in the figure below:

    net

Configuration for using MQ SDK in Visual Studio 2015

  1. Create an ASP.NET Web Forms project using VS2015.

    aspnet_1

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

    aspnet_2

  3. Right click the project and select Add > Existing Item, and add all files in the interface folder in the downloaded SDK.

    Refer to step 2 above for configuring normal .NET project.

  4. Add code for enabling and disabling SDK in the file Global.asax.cs.

    Note:

    It is suggested to wrap the SDK code to a singleton class, so as to prevent it from being collected by the garbage collector due to scope issues. The “example” folder provides Example.cs, which implements a simple singleton. To use it, you need to include the Example.cs in your project.

    1. sing System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Web;
    5. using System.Web.Optimization;
    6. using System.Web.Routing;
    7. using System.Web.Security;
    8. using System.Web.SessionState;
    9. using ons; // This is the namespace where the SDK located
    10. using test; // This is the namespace where a wrapped SDK class is located, see the Example.cs in the “example” folder in SDK
    11. namespace WebApplication4
    12. {
    13. public class Global : HttpApplication
    14. {
    15. void Application_Start(object sender, EventArgs e)
    16. {
    17. // Code that runs on application startup
    18. RouteConfig.RegisterRoutes(RouteTable.Routes);
    19. BundleConfig.RegisterBundles(BundleTable.Bundles);
    20. try
    21. {
    22. // Code for starting the SDK, and the following is the code after the SDK is wrapped in a simple way
    23. OnscSharp.CreateProducer();
    24. OnscSharp.StartProducer();
    25. }
    26. catch (Exception ex)
    27. {
    28. // Processing exception
    29. }
    30. }
    31. protected void Application_End(object sender, EventArgs e)
    32. {
    33. try
    34. {
    35. // Code for shutting down the SDK
    36. OnscSharp.ShutdownProducer();
    37. }
    38. catch (Exception ex)
    39. {
    40. // Processing exception
    41. }
    42. }
    43. }
    44. }
  5. Write a test program and compile it.

  6. Move the dll in the SDK to the same directory as the executable files, or to the system directory for execution.

    dll Deployment

  7. Click Tools > Options > Projects and Solutions > Web Projects, and select the 64 bit version of IIS Express for web sites and projects.

    iis_1

    iis_2

Thank you! We've received your feedback.