How to call M3 API from .NET

Here is an example to call M3 API from .NET in C#.

Background

To call M3 API in .NET there are several options: 1) we can use Interop to wrap the COM unmanaged library, 2) we can use netmodules which were introduced in the M3 API Toolkit version 9.0.1.1, or 3) we can use the native .NET managed library which were introduced in the M3 API Toolkit version 9.0.3.0. I suggest the latter option.

Example

  1. Download and install the M3 API Toolkit version 9.0.3.0 or later.
  2. That version includes the .NET library MvxSockN.dll:
  3. You can use .NET Reflector to introspect the assembly:
  4. That version also includes documentation specifically for .NET:
  5. That version also includes C# examples:
  6. If you are using Microsoft Visual C# Express, add a New Reference to the DLL:
  7. Then add the namespace Lawson.M3.MvxSock to the source code:
    using Lawson.M3.MvxSock;
  8. Then start using MvxSock with IntelliSense:
  9. Here’s my sample source code:
    using System;
    using Lawson.M3.MvxSock;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                SERVER_ID sid = new SERVER_ID();
                uint rc;
                rc = MvxSock.Connect(ref sid, "hostname", 6800, "userid", "*********", "CRS610MI", null);
                if (rc != 0)
                {
                    MvxSock.ShowLastError(ref sid, "Error no " + rc + "\n");
                    return;
                }
                rc = MvxSock.Access(ref sid, "LstByNumber");
                if (rc != 0)
                {
                    MvxSock.ShowLastError(ref sid, "Error no " + rc + "\n");
                    MvxSock.Close(ref sid);
                    return;
                }
                while (MvxSock.More(ref sid))
                {
                    Console.WriteLine(MvxSock.GetField(ref sid, "CUNO") + ", " + MvxSock.GetField(ref sid, "CUNM"));
                    MvxSock.Access(ref sid, null);
                }
                MvxSock.Close(ref sid);
            }
        }
    }
  10. Here’s a sample result of calling CRS610MI.LstByNumber:

That’s it!

Related articles

Published by

thibaudatwork

M3 Technical Consultant

35 thoughts on “How to call M3 API from .NET”

  1. HI
    THX your post!
    I want to know different return rc = MvxSock.Access(ref sid, “LstByNumber”); different error msg.

    Like

    1. Hi Vincent. I don’t understand your question. But I invite you to read the developer’s guide that’s in the M3 API Toolkit. In the doc folder there’s a PDF that explains everything about the libraries, Java, ActiveX, .NET, etc. There you will get details about the methods, parameters, etc.

      Like

      1. THX
        I find this one

        Code
        Explanation
        0
        OK(no error)
        1
        General error on input data (user error)
        2
        No connection to server exists
        3
        Receive buffer is to small(first part of message from server is returned as valid data)
        4
        No receive buffer exists
        5
        Crypto error (internal error. Read plain text for more details)
        6
        Illegal type of transaction when calling function
        7
        Other error (severe) (must read plain text message)
        11-19
        Function specific errors from user input

        My M3 API Toolkit is too older can you send it to me the M3 API Toolkit ufo343425185@gmail.com.

        Best Regards!!!

        Like

        1. Hi Vincent, I cannot send you the API Toolkit as it’s copyrighted material of Infor. However, I can help you find the proper channel. I can also assist you via Infor Services. Send me an email to thib@infor.com. /Thibaud

          Like

    1. Hi Matthieu, it’s possible to include that library in a VB script, we do that often with Visual Basic for Applications (VBA) in Excel via the VBA via Tools > References. But I don’t know if or how to do it with SSIS. /Thibaud

      Like

  2. Hi,

    We use Windows login to connect to Lawson M3.

    Once logged in from LSO users access some customer interfaces which are developed in .net.

    Right now we need to pass the credentials to the interfaces.

    Is it possible to use Single Sign on (SSO) with the M3 API Toolkit.

    Regards,
    Yohan

    Like

    1. Hi Yohan, I’m sure it’s technically possible, I just don’t know how to implement that. You’re in Windows territory now, not Infor’s. I’m not familiar with Windows authentication, SSO, Kerberos, NTLM, etc. /Thibaud

      Like

  3. I created a vb.net application using the MvxSockX_SRV.dll in a .net framework 4 environment. I am getting the error “Attempted to read or write protected memory. This is often an indication that other memory is corrupt” on the MvxSock.Access call. Any suggestions? Thanks.

    Like

  4. Need to return an unlimited number of rows from a lst api. How would I go about doing that? Right now it’s returning 100.

    Like

  5. Hi , I have a problem with the component, returns this message ” Microsoft.SqlServer.Dts.Pipeline.CannotCreateUserComponentException . . Unable to create the class of the user component Make sure your script has a class marked with SSISScriptComponentEntryPointAttribute ”
    Thanks for help
    Daniel

    Like

      1. Hi Thibaud,
        This problem is now solved. But when I run the component, I have this message “Impossible de charger le fichier ou l’assembly ‘Interop.MVXSOCKX_SVRLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ ou une de ses dépendances’
        I know that MVXSRVSOCKX_SRVLib is a COM component I am using with .NET code but I already imported System.Runtime.InteropServices which was generally able to make it work.
        Regards Daniel

        Like

        1. Daniel, I really don’t know. Some basic questions: Are you using the correct DLL for .NET? It should be the filename ending with N for .NET, MvxSockN.dll. Also, did you try the 64bit version, MvxSockNx64.dll, in case you have 64bit Windows? Also, do you have the version of the M3 API Toolkit that matches the M3 BE server?

          Like

  6. Hi All,
    Can you please mail me that .net DLL file because i have “MvxSockx64.dll” which i can’t able to use on .net as reference.
    Can anyone please mail me the .net DLL files on “yogesh.malik@outlook.com”, it’s kinda urgent.

    Thanks in advance.

    Like

    1. Hi Yogesh, the .NET version of the DLL contains the letter N, MvxSockNx64.dll. Also, we are not allowed to distribute Infor’s proprieaty software. You can download it from the Infor Xtreme downloads website. Otherwise, it’s in every M3 project installation. Otherwise, use the open source alternative from benmat on GitHub.

      Like

      1. hi thibaudatwork,
        I’ve already register to that site Xtreme downloads, but the site is i think under maintenance and i can’t login to that site.
        I know you are not allow to distribute these kind of software, but actually i need that DLL urgent only .net DLL please share me only those .net DLL.

        Scenario,
        Actually i just want to built and application on .net through which i can upload the data from .net application to INFOR M3 by using M3 program and transaction.

        Please help me.

        Like

        1. Sorry. Urgency on your part doesn’t change the intellectual property laws. Did you try the open source alternative? Otherwise, to add data to M3 you don’t absolutely need that DLL, you can use the REST endpoint. You don’t need a DLL for that, just HTTP. Have you tried that?

          Like

        2. So? Yogesh? Did you try my suggestions? Also, which company/customer is this project for? We can start there. Every customer has the M3 API Toolkit installed on the D: drive of the M3BE and/or MAK servers. Did you check again there?

          Like

Leave a Reply

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s