Reputation: 11
Here is a code snippet. Please tell me whats the difference between these two codes and also which content suitable for these code snippets. "application/xml" or "plain/text"
[OperationContract]
[WebInvoke(Method="POST", UriTemplate="DoSomething")]
public XElement DoSomething(XElement body) {
...
return new XElement("Result");
}
[OperationContract]
[WebInvoke(Method="POST", UriTemplate="DoSomething")]
public string DoSomething(string body) {
...
return "thanks";
}
Upvotes: 1
Views: 2443
Reputation: 142222
WCF thinks everything by default is XML so both endpoints will return XML. The second one will return
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">thanks</string>
With the content type application/xml. And if you want POST a string to it, you will have to send it a XML serialized string. Goofy isn't it.
If you really want to return just a string, then use Stream as your return type. Or take a look at WCF in .Net 4. It looks like they made it a whole lot easier to return other types.
Upvotes: 1
Reputation: 596
Both methods respond to a POST request on a URI of the format '{BASE_URI}/DoSomething' (just a guess)
Regarding the 'content-type' setting: application/xml for the first one and plain/text for the second one.
Upvotes: 0