I am trying to have a console application to send an XML file to a web application developed in ASP.NET MVC 3 and get another XML as a response.
Error in console application:
The remote server responded with an error: (500) Internal server error.
When I run Fiddler2, I see this error:
The reference to the object is not installed in the instance of the object.
Code in console application:
static void Main(string[] args) { var wc = new WebClient(); byte[] response = wc.UploadFile("http://mysite.com/Tests/Test", "POST", "teste.xml"); string s = System.Text.Encoding.ASCII.GetString(response); Console.WriteLine(s); Console.ReadKey(); }
Code in MVC:
[HttpPost] public ActionResult Test(HttpPostedFileBase file) { XElement xml = XElement.Load(new System.IO.StreamReader(file.InputStream)); var test = new MyTest(); return File(test.RunTest(xml), "text/xml", "testresult.xml"); }
RunTest()
works well, since this method works when I upload a file through a form (in a method with the same name, using the GET method). RunTest()
returns the XML with the response.
When I debug an MVC application, I see a problem: the file
variable is null!
How to fix it? What do I need to change in my console application so that it really sends the file? Or can this change the MVC method?
And, before trying to use WebClient
, I tried this code here: http://msdn.microsoft.com/en-us/library/debx8sh9.aspx and had the same results.