Click here to Skip to main content
15,887,251 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a mvc 4 rest service, now i have a c# desktop application, which i want to use via that service, and i have a 'test' function inside the service, now i want to call it from the application and get the response in xml document, how can i do this?

for example the url is: "http://localhost:3466/api/acp/test"
and the response is: image

any idea? i managed to the only the string "successfully executed", with a code that i deleted because its no help, i need to have the full response in xml object. tnx in advance.
Posted
Comments
George Jonsson 25-Oct-15 15:19pm    
So what is the response you want?
SrgjanX 25-Oct-15 15:54pm    
xml object.
FranzBe 25-Oct-15 16:51pm    
perhaps this
https://msdn.microsoft.com/en-us/library/hh534080.aspx
might help.

1 solution

just tried this:
C#
static void testGetXmlDocFromWebRequest()
{
  string response = string.Empty;
  string url = "your-url";
  WebRequest request = WebRequest.Create(url);
  try
  {
    using (StreamReader streamIn = new StreamReader((request.GetResponse()).GetResponseStream()))
    {
      response = streamIn.ReadToEnd();
      streamIn.Close();
    }
  }
  finally
  {
    request.Abort();

  }
  XDocument xDoc = XDocument.Parse(response);
}

and it worked. Taken from: here
 
Share this answer
 
Comments
SrgjanX 25-Oct-15 17:23pm    
yeah, and i tried this, and @FranzeBe's reply, and i still throws exception: "Root element is missing." i know this means wrong xml formatting, what do u think?
SrgjanX 25-Oct-15 17:23pm    
i checked with online xml validator, it didnt found problem with the response, so whats the problem?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900