MATLAB: How to access a Matlab Production Server instance on a virtual machine with RESTful API

jsonMATLAB CompilerMATLAB Production Serverrestful api

I have successfully installed the Matlab Production Server on a remote virtual machine. I want to create a client using RESTFUL API & JSON to run a web application. For this, I have been following the example for calculating bond price found here
When I run the HTML script on my web browser, nothing happens. I believe the issue is with connecting to the Matlab Production Server instance on my virtual machine. The .ctf function is in the auto-deploy folder in the server instance (a different location from where the Matlab Production Server is installed). How should I specify the url in the javascript code? http://my.ip.address:9910/path/to/server/BondTools/pricecalc ??
Any help would be greatly appreciated. Thanks!

Best Answer

  • In this Bond pricing example, assuming the hostname of your virtual machine is VM_HOST, you need to change the following line of calculatePrice.js.
    var url = "http://VM_HOST:9910/BondTools/pricecalc";
    Because calling MATLAB Production Server is based on HTTP or HTTPS on TCP, so you don't need to specify the actual server path of MATLAB Production Server. In this example, BondTools is CTF name and pricecalc is MATLAB function name.
    Also, since you're accessing MATLAB Production Server from different host, I mean, client (HTML file) is on physical machine (let's say hostname is YOUR_HOST) and MATLAB Production Server is on virtual machine(VM_HOST, you need to set Cross-Origin Resource Sharing (CORS) properly in config/main_config file. If you want to allow accessing from only YOUR_HOST, you need to change cors-allowed-origins as follows,
    --cors-allowed-origins http://YOUR_HOST
    or if you want to allow accessing from any host,
    --cors-allowed-origins *
    If you're using MATLAB Production Server R2017a, you can use dashboard and it's easier to deploy ctf, change HTTP/HTTPS settings and resources, and monitor the status of MATLAB Production Server instances. To setup MATLAB Production Server dashboard, please see this doc; Set Up and Log In to MATLAB Production Server Dashboard