When writing .NET interfaces to invoke MATLAB® code, remember these guidelines:
The method name exposed by the interface must match the name of the MATLAB function being deployed. The method must have the same number of inputs and outputs as the MATLAB function.
The method input and output types must be convertible to and from MATLAB.
The number of inputs and outputs must be compatible with those supported by MATLAB.
If you are working with MATLAB structures, remember that the field names are case sensitive and must match in both the MATLAB function and corresponding user-defined .NET type.
The name of the interface can be any valid .NET name.
Your code should support exception handling.
Complete these steps to prepare your MATLAB Production Server™ .NET development environment.
Install Microsoft Visual Studio. See http://www.mathworks.com/support/compilers/current_release/ for an up-to-date listing of supported software, including IDEs and Microsoft® .NET Frameworks.
Verify that your application is deployed to a running server instance.
You should declare exceptions for the following errors:
For This Error | Use This Method | To Declare This Exception |
---|---|---|
MATLAB errors | MATLABException | MathWorks.MATLAB.ProductionServer.Client. MWClient.MATLABException |
Transport errors occurring during client-server communication | WebException | System.Net.WebException |
The connections between a .NET client and the servers with which
it interacts are managed by one or more instances of MWHttpClient
.
You can use a single instance to communicate with more than one server
or you can create multiple instances to manage multiple servers. Proxy
objects, created using an instance of MWHttpClient
,
communicate with the server until the Dispose
method
of that instance is invoked. Therefore, it is important to call the Dispose
method
only when the MWHttpClient
instance is no longer
needed, to reclaim system resources.
Call the Dispose
method on unneeded client
instances to free native resources, such as open connections created
by an instance of MWHttpClient
.
You call Dispose
in either of two ways:
Call Dispose
Directly —
Call the method directly on the object whose resources you want to
free:
client.Dispose();
The using
keyword —
Implicitly invoke Dispose
on theMWHttpClient
instance
with the using
keyword. By doing this, you don't
have to explicitly call the Dispose
method—the
.NET Framework handles cleanup for you.
Following is a code snippet that demonstrates use of the using
keyword:
using (MWClient client = new MWHttpClient(new TestConfigDispose())) { // Use client to create proxy instances and invoke // MATLAB functions.... }
Caution
Calling Dispose on instances of |
For information regarding supported MATLAB types for client and server marshaling, see Unsupported MATLAB Data Types for Client and Server Marshaling
The API doc for the .NET client is installed in
.$MPS_INSTALL
/client