Domanda

I am trying to create a restful service using service stack. How do I configure the end point of the service that I am trying to create? The default is 8080 and I want to be able to run multiple services at the same host.

Thanks

È stato utile?

Soluzione

This depends on how you use ServiceStack. ServiceStack can be included in an existing ASP.NET Web Application as an HttpModule or it can be configured to be a Self Hosted application.

Self Hosted

As a self hosted application you would define the port your require to run your service on when specifying the HTTP listener configuration in the AppHost:

public static void Main()
{
    // Very simple self hosted console host
    var appHost = new AppHost();
    appHost.Init();
    appHost.Start("http://*:8080/"); // Update the port number here, change 8080
    Console.ReadKey();
}

ASP.NET Web Application

When running your ServiceStack application inside an ASP.NET Web Application (with or without MVC) on Windows you will use IIS (or Cassini/ IISExpress during development) on Mono platforms, such as Mac OS X, you will use fastcgi-server (or XSP during development). In which case you can configure your server port this way:

Development:

In development, you can configure the port in your project settings.

Visual Studio:

This step will depend on the version of Visual Studio you are using, but they are all similar.

  • In the Solution Explorer right-click on your project
  • Then choose Properties
  • Then select the Web tab

You will then see options similar to these screenshots, depending on your version.

If you have IISExpress configured for development, change where it shows 51283, in the Project URL, in this screenshot to the port number you require. IISExpress

If you have Cassini, the Visual Studio Development Server, for development Older versions of Visual Studio, change where it shows 63919 in this screenshot to the port number you require. Casini Port

Xamarin Studio/ MonoDevelop

  • In the Solution Explorer right-click on your project
  • Then choose Options
  • Then select the XSP Web Server tab, under the Run section
  • Update the Port Number field

XSP Port

Production:

You will configure the port number in the hosting server configuration. For IIS please see here, for others you will need to refer to their documentation.

I hope this helps.

Altri suggerimenti

With a single configuration, you can create multiple services with same root url. Example is http://localhost:8080/api/customers and http://localhost:8080/api/vendors. root level end point in your application is configurable. For example instead of /api you can use any path. refer to this wiki page from servicestack.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top