Click here to Skip to main content
15,916,463 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
For the life of me I can not find a way to remove the automatically generated portion of my Get method.
given following code
C#
[WebGet(UriTemplate = "{id}", BodyStyle=WebMessageBodyStyle.Bare, ResponseFormat=WebMessageFormat.Xml)]
public string Get(string id) {
return "blah";
}


I get following response.
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">blah</string>

How can I get just "blah".
Many Thanks.
Posted
Updated 29-Mar-11 13:27pm
v2
Comments
HimanshuJoshi 29-Mar-11 19:28pm    
Edited to improve readability.

I think this will work, note the Stream as return argument.
[WebGet(UriTemplate = "{id}", BodyStyle = WebMessageBodyStyle.Bare)]
public Stream Get(string id)
{
  OutgoingWebResponseContext context = WebOperationContext.Current.OutgoingResponse;
  context.ContentType = "text/plain";
  return new System.IO.MemoryStream(ASCIIEncoding.Default.GetBytes("blah"));
}
 
Share this answer
 
Comments
cechode 1-Apr-11 19:52pm    
Awsome! many thanks. works like a charm
Instead of changing the method signature, I would do this:

HttpWebResponse restResponse = (HttpWebResponse)restRequest.GetResponse();
string value = null;

using (var st = restResponse.GetResponseStream())
{
    StreamReader sr = new StreamReader(st);
    value = sr.ReadToEnd();
}

XmlDocument doc = new XmlDocument();
doc.LoadXml(value);
value = doc.InnerText;
 
Share this answer
 

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