I need to be able to pass XML to a RESTFul WCF service as a string, however I am struggling to do so. Can someone please let me know how I could do this? It must be sent as a string, I cannot wrap it in a data contract etc. Example of the service contract below
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "lookup",
BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Xml)]
Stream LookupPostcode(string requestXml);
Many thanks in advance
Wrapping the xml in CDATA tags stops the parser from treating it as xml:
It's a major hack, but you can wrap your XML inside a
<string>
tag like this.Try using
XElement
orStream
as your method parameter....
... Not sure what you are trying to do inside of the method or I could probably provide more help.
This is completely off-topic, but trying to bend WCF to be RESTful will be a constant battle and you will ultimately surrender. It's the message-oriented RPC- and SOAP-based configure-everything-in-XML nature of WCF that makes it so hard to write simple REST services.
If you're not neck-deep in your project, try researching other alternatives and abandon WCF for that purpose.