C # how to call MVC Action method from console application

I am working on a console application that retrieves some data and calls the MVC3 Action method and passes the selected data as a parameter to this action method. But my problem is how the console application finds out that the data is successfully transmitted \ MVC action method correctly, and on the server mvc-application works or not

here is my code:

public static void Main()
{
// Mvc application object intialization
                HomeController object_Mail = new HomeController();
            // Mvc action method call
           object_Mail.mailgateway(mvcemails); //mvcemails parameter passed to Actionmethod               
}

I beg you ...

Thanks Raj

+5
source share
3 answers

MVC, , - . . , mvc , - , , HTTPRequest..

HTTPRequest :

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://"+ <your mvc action endpoint> )
request.Method = "GET";
//specify other request properties

try
{
    response = (HttpWebResponse)request.GetResponse();
}

, URL :

string url = string.Format(
            "http://mysite/somepage?key1={0}&key2={1}",
            Uri.EscapeDataString("value1"),
            Uri.EscapeDataString("value2"));

webRequest.Method = "POST";
var data=string.Format("key1={0}&key2={1}",Uri.EscapeDataString("value1"),Uri.EscapeDataString("value2")");
StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream());
requestWriter.Write();
requestWriter.Close();
+8

, WebClient HttpWebRequest .

0

, . , - , , Moq

DLL, MVC, unit test, . Moq , , , ..

, , . .

, stackoverflow asp.net mvc.

0

All Articles