0
Reply

How to hit a controller on another server using HttpWebreque

Surender Bhyan

Surender Bhyan

Apr 6 2015 1:54 AM
493

Hi,

I am very new here with MVC.

I want to call a method using httpwebrequest that exist on another server.

Suppose there are two server with IP 10.100.248.103 and 10.100.248.104

Both method given below exist on both server.

public bool updateAllServer() { 
   HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://10.100.248.104/VirtaulDirectoryPath/UpdateSharedVars/updateME"); 
   request.ContentType= "application/json";
   request.AllowAutoRedirect = false;
   WebResponse response = request.GetResponse(); 
   this.Status = ((HttpWebResponse)response).StatusDescription; return true; 
}
public bool updateMe() {
   allVariables.SetAll();
   return true; 
}

I am on server 10.100.248.103, and hit the updateAllServer() that will do a call UpdateMe method on server 10.100.248.104.

"http://10.100.248.104/VirtaulDirectoryPath/UpdateSharedVars/updateME"

code is executing fine but control is not going in updateMe method. 

In simple words , I want to Hit UpdateMe method that exist on 10.100.248.104 from server 10.100.248.103. I am not sure how to achieve this functionality.Please help I am using MVC4.