Create Remotable .NET Assembly
This example shows how to create a remotable .NET assembly using MATLAB® Compiler SDK™.
Preparation
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.
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 filemakesquare.m
in theMagicSquareRemoteComp
subfolder:function y = makesquare(x) y = magic(x);
Build Remotable Component Using Library Compiler App
Click the Library Compiler app in the apps gallery, or type
libraryCompiler
at the MATLAB command prompt.In the Additional Runtime Settings area, select Enable .NET Remoting.
Build the .NET component using the following values.
Field Value Library Name MagicRemoteComp
Class Name MagicClass
File to Compile makesquare.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
— TheMWArray
API component implementation assembly used by the server.IMagicRemoteComp.dll
— TheMWArray
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
compiler.build.dotNETAssembly
| Library Compiler | mcc
| deploytool