Running Web Api 2 on Linux (mono/xsp4?)

865 Views Asked by At

I'm new to both .NET Web API development and mono, so this question might turn out to be too basic, but I've been unable to find any instructions for deploying a Web API 2 project in xsp4 on Linux. Is it even possible?

I was able to easily run ASP.NET apps by addressing their .aspx files, but a Web API app, once you publish it, is just a bunch of .config and .dll files.

How do you start it inside xsp4 server such that all routes specified within it are mapped correctly? Is it done from command line, or do you need a config file?

1

There are 1 best solutions below

0
On BEST ANSWER

Here's the basic method that has worked:

  1. Create a config file for xsp4, let's call it webapi.webapp. Inside the config file, define this application:

    <apps>
    <web-application>
    <name>MyWebAPI</name>
    <vhost>localhost</vhost>
    <vport>9090</vport>
    <vpath>/</vpath>
    <path>/home/me/MyWebAPI</path>
    </web-application>
    </apps>
    

    To be honest, I don't actually know what vhost and vport do, but I don't need to mess with that for now. The key is path and vpath. Path is the physical location of the directory with your whole published WebAPI project on the hard drive of the host system. Vpath is what you specify in the URL to reach this web app you're defining. Since I specified / as the vpath, that means pretty much all paths on this server will go to my app. So if inside the app I'm defining a route such as "/webapi/v10/users", then with / for vpath, it'll be accessed via "localhost:9090/webapi/v10/users". (See next step for how to set the port.)

  2. You launch xsp4 via the following command:

    xsp4 --appconfigfile webapi.webapp --port 9090
    

    Use appconfigfile to provide the path to the config file created in step 1, and set the port on which the server will listen on here. I'm not sure how this relates to vport in the config file, I did not bother to figure it out that far.

If you need HTTPS, xsp4 seems to support it as well (based on its man page), but I haven't tried it yet. Otherwise, I think you can also set up Apache as a reverse proxy for it even if you don't use mod_mono.