Main Content

Create Remotable .NET Assembly

This example shows how to create a remotable .NET assembly using MATLAB® Compiler SDK™.

Preparation

  1. Decide whether you plan to use the MWArray API or the native .NET API. For more information, see Compare MWArray and Native .NET API for Remotable Assemblies.

    • If using the MWArray API, copy the following folder that ships with the MATLAB product to your working folder:

      matlabroot\toolbox\dotnetbuilder\Examples\VSVersion\NET\MagicRemoteExample\MWArrayAPI\MagicSquareRemoteComp
      

      After you copy the files, at the MATLAB command prompt, change the working folder (navigate) to the new MagicSquareRemoteComp subfolder in your working folder.

    • If using the native .NET API, copy the following folder that ships with the MATLAB product to your working folder:

      matlabroot\toolbox\dotnetbuilder\Examples\VSVersion\NET\MagicRemoteExample\NativeAPI\MagicSquareRemoteComp

      After you copy the file, at the MATLAB command prompt, change the working folder (navigate) to the new MagicSquareRemoteComp subfolder in your working folder.

  2. Write the MATLAB function. Your MATLAB code does not require any additions to support .NET remoting. The following code for the makesquare function is in the file makesquare.m in the MagicSquareRemoteComp subfolder:

    function y = makesquare(x)
    y = magic(x);
    

Build Remotable Component Using Library Compiler App

  1. Click the Library Compiler app in the apps gallery, or type libraryCompiler at the MATLAB command prompt.

  2. In the Additional Runtime Settings area, select Enable .NET Remoting.

    Additional runtime settings section with the Enable .NET Remoting box marked

  3. Build the .NET component using the following values.

    FieldValue
    Library NameMagicRemoteComp
    Class NameMagicClass
    File to Compilemakesquare.m

    For more details, see the instructions in Generate .NET Assembly and Build .NET Application.

Build Remotable Component Using compiler.build.dotNETAssembly

As an alternative to the Library Compiler app, you can create a .NET assembly using a programmatic approach.

From the MATLAB prompt, issue the following command:

buildResults = compiler.build.dotNETAssembly('makesquare.m', ...
    'AssemblyName','MagicRemoteComp', ...
    'ClassName','MagicClass', ...
    'EnableRemoting','on');

Note

The generated assembly does not include MATLAB Runtime or an installer. To create an installer using the buildResults object, see compiler.package.installer.

Files Generated by the Compilation Process

After compiling the components, ensure you have the following files in your for_redistribution_files_only folder or designated output folder:

  • MagicRemoteComp.dll — The MWArray API component implementation assembly used by the server.

  • IMagicRemoteComp.dll — The MWArray API component interface assembly used by the client.

  • MagicRemoteCompNative.dll — The native .NET API component implementation assembly used by the server.

  • IMagicRemoteCompNative.dll — The native .NET API component interface assembly used by the client. You do not need to install MATLAB Runtime on the client when using this interface.

See Also

| | |