How do I access a Matlab Production Server instance on a virtual machine with RESTful API?

11 views (last 30 days)
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 https://www.mathworks.com/help/mps/restfuljson/example-web-based-bond-pricing-tool-using-javascript.html
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!

Accepted Answer

Kojiro Saito
Kojiro Saito on 14 Sep 2017
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
  3 Comments
Kevin Chng
Kevin Chng on 24 Sep 2019
Hi, i'm running the same example, however, it is working if I use the test client in the MATLAB production server compiler in MATLAB. Now, if I set up the dasboard server, I put * for cors-allowed-origins. The javascript and HTML is in the server, therefore I use var url = "http://localhost:9910/BondTools/pricecalc"; However, it is not working. Any insight to address it?
Kojiro Saito
Kojiro Saito on 24 Sep 2019
Hi Kevin, are you opening Web browser on a different machine from the server? If so, you need to change the URL from localhost to the hostname or IP address of the server. Assume the hostname of the server is mpsserver, then you need to change from
var url = "http://localhost:9910/BondTools/pricecalc";
to
var url = "http://mpsserver:9910/BondTools/pricecalc";

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!