How To Call Servicestack service deployed on remote server from MVC4.net application deployed on another server?

amol

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.

mythz

Calling ServiceStack Services out-of-process

If ServiceStack and MVC are not hosted together in the same Web Application then you would just access the ServiceStack Service as you would from any .NET Service Client using the ServiceStack Server DTO's and a .NET Service Client, e.g:

var response = client.Post(new TravelServiceRequest { ... });

Another alternative to sharing the Server DTO .dll is to use the VS.NET Integration offered by Add ServiceStack Reference which lets you generate Server DTO's from a remote url.

ServiceStack + MVC In Process

If ServiceStack and MVC are hosted together in the same AppDomain refer to the ServiceStack Integration with MVC which allow your Controllers can access most of ServiceStack functionality by inheriting from ServiceStackController.

You can then Execute a ServiceStack Service in-process in your MVC Controllers with:

var response = base.Execute(new TravelServiceRequest { ... });

This is equivalent to resolving the ServiceStack Service from the IOC and calling it directly which you can do instead, e.g:

using (var service = base.ResolveService<TravelServices>())
{
    var response = service.Post(new TravelServiceRequest { ... });
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to go live with the sample web application for testing deployed on remote server?

From Dev

how to go live with the sample web application for testing deployed on remote server?

From Dev

How to call a clickonce deployed application from another application in VB.NET?

From Dev

MVC4 deployed to remote IIS 7.5, gives 401.2 error when accessing sql server

From Dev

How to get all deployed application in tomcat server

From Dev

How to get all deployed application in tomcat server

From Dev

How Can I call a controller function that is located on another project that is deployed on the same server?

From Dev

How to run app.js deployed on remote server from local bash?

From Dev

MVC: workflow is not working in deployed server

From Dev

CSV file fails to import once MVC Application deployed to Server

From Dev

How can I update a SQL Server Project in Visual Studio 2013 if the deployed database is changed from another source?

From Dev

How to get the full URL from deployed WAR file in a tomcat server

From Dev

Calling Deployed API from each server in AWS

From Dev

Logging to file on deployed server

From Dev

How to secure the war file deployed in tomcat server?

From Dev

How to secure the war file deployed in tomcat server?

From Dev

How to consume a .net web service from a remote server with javascript

From Dev

rails view looks different when deployed on remote server

From Dev

Wildfly deployed war successfully on remote server but 404 not found

From Dev

MAC | Access application deployed on Docker from another application on VirtualBox machine

From Dev

Sending signals from a remote server to a .NET application

From Dev

ASP.NET MVC call REST Service from server side

From Dev

make sure the service has been deployed successfully, and the server is runnig

From Dev

Spring Boot MVC Application returns HTTP 404 when deployed to an external Tomcat/tc Server instance

From Dev

No response from Service Fabric Application when deployed to Azure

From Dev

No artifacts found to be deployed in this server. Ignoring Carbon Application

From Dev

Spring application fails on startup with NoClassDefFoundError when deployed in tc Server with Insight

From Dev

Grails database migration on deployed server

From Dev

Grails database migration on deployed server

Related Related

  1. 1

    how to go live with the sample web application for testing deployed on remote server?

  2. 2

    how to go live with the sample web application for testing deployed on remote server?

  3. 3

    How to call a clickonce deployed application from another application in VB.NET?

  4. 4

    MVC4 deployed to remote IIS 7.5, gives 401.2 error when accessing sql server

  5. 5

    How to get all deployed application in tomcat server

  6. 6

    How to get all deployed application in tomcat server

  7. 7

    How Can I call a controller function that is located on another project that is deployed on the same server?

  8. 8

    How to run app.js deployed on remote server from local bash?

  9. 9

    MVC: workflow is not working in deployed server

  10. 10

    CSV file fails to import once MVC Application deployed to Server

  11. 11

    How can I update a SQL Server Project in Visual Studio 2013 if the deployed database is changed from another source?

  12. 12

    How to get the full URL from deployed WAR file in a tomcat server

  13. 13

    Calling Deployed API from each server in AWS

  14. 14

    Logging to file on deployed server

  15. 15

    How to secure the war file deployed in tomcat server?

  16. 16

    How to secure the war file deployed in tomcat server?

  17. 17

    How to consume a .net web service from a remote server with javascript

  18. 18

    rails view looks different when deployed on remote server

  19. 19

    Wildfly deployed war successfully on remote server but 404 not found

  20. 20

    MAC | Access application deployed on Docker from another application on VirtualBox machine

  21. 21

    Sending signals from a remote server to a .NET application

  22. 22

    ASP.NET MVC call REST Service from server side

  23. 23

    make sure the service has been deployed successfully, and the server is runnig

  24. 24

    Spring Boot MVC Application returns HTTP 404 when deployed to an external Tomcat/tc Server instance

  25. 25

    No response from Service Fabric Application when deployed to Azure

  26. 26

    No artifacts found to be deployed in this server. Ignoring Carbon Application

  27. 27

    Spring application fails on startup with NoClassDefFoundError when deployed in tc Server with Insight

  28. 28

    Grails database migration on deployed server

  29. 29

    Grails database migration on deployed server

HotTag

Archive