I am new to Servicestack and trying to implement it for my current project.Now I have my MVC.NET application deployed on one server (say http://server1:8080) and servicestack service deployed on different one (say http://server2:9080).
I have already gone through
https://github.com/ServiceStack/ServiceStack/wiki/Mvc-integration
but i am not able to understand how to change that to call service from http://server2:9080
how to call service from my MVC controller?
Service code is as following
// APPHOST.cs
public class AppHost : AppHostBase
{
public AppHost() : base("Flight app host",
typeof(flightService).Assembly) { }
public override void Configure(Container container)
{
}
}
// Request DTO
[Route("/flights/","POST")]
[Route("/flights/{departure}/{arrival}","POST")]
public class TravelServiceRequest : IReturn<TravelServiceResponce>
{
public string departure { get; set; }
public string arrival { get; set; }
}
// Response DTO
public class TravelServiceResponce
{
public string departure { get; set; }
public string arrival { get; set; }
public string airline { get; set; }
public decimal fare { get; set; }
public DateTime arrivalTime { get; set; }
public DateTime departureTime { get; set; }
}
// service
public class flightService:Service
{
public object Post(TravelServiceRequest request)
{
var response = new TravelServiceResponce
{
departure =request.departure,
arrival =request.arrival,
airline="jet airways",
fare =677,
arrivalTime =new DateTime(2014,12,12,5,6,2),
departureTime = new DateTime(2014,11,12,5,6,2)
};
return response;
}
}
// Gloable.asax.cs file
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
var appHost = new AppHost();
appHost.Init();
}
}
In my MVC apllication
public class HomeController : Controller
{
public ActionResult Index()
{
//call service from here
return View();
}
}
I have c# code to call this service but i am not sure if this is the best way to use in MVC controller
var client = new JsonServiceClient("http://server2:9080/");
var responce = client.Post(new TravelServiceRequest
{
departure = departure,
arrival = arrival
});
Please help me with best way to call remote service in MVC.