Table of Contents

Getting Started with MM7Server

Standalone MMS Server

The MMS messages from MMSC can be received with standalone MM7Server class. This class has several events that will raise as soon as appropriate MM7 message is received. In the event handlers you can save the MMS content or perform any other processing. You need to start the server with the method @Inetlab.MMS.MM7Server.Start().

public class MMSServerForVASPExample
{
    private MM7Server _server;

    public MMSServerForVASPExample()
    {  
         
        _server = new MM7Server("http://localhost:9090/");
        _server.ServerMode = MM7ServerMode.VASP;
        _server.AuthScheme = AuthenticationSchemes.Basic;
        _server.Events.OnAuthentication = OnAuthentication;
        _server.Events.OnDeliverRequest = OnDeliverRequest;
    }

    public void Start()
    {
        _server.Start();
    }

    private Task<string> OnAuthentication(AuthenticationEventArgs e)
    {
        //check username
        if (e.UserName == "test")
        {
            string password = "password from db";

            // return password
            return Task.FromResult(password);
        }

        // not authenticated.
        return Task.FromResult<string>(null);
    }


    /// <summary> Raises when MMSC delivers MMS to VASP endpoint.</summary>
    private Task<DeliverResponse> OnDeliverRequest(DeliverReqEventArgs e)
    {
        //MMS received from MMSC on VASP MMS Endpoint.

        // Save all MMS message parts to the Delivered folder
        string path = Path.GetFullPath("Delivered");
        path = Path.Combine(path, e.Request.TransactionID);
        Directory.CreateDirectory(path);

        foreach (MMSPart part in e.Message.Parts)
        {
            part.Save(Path.Combine(path, part.GetFileName()));
        }

        return Task.FromResult(new DeliverResponse(e.Request));
    }
}

MMS Server in ASP.NET Core

It is possible to implement ASP.NET Core middleware with MM7Server class. See the MM7Server.AspNetCore sample application in the Samples folder.