I want to return unescaped html in the WCF response, therefore I need CDATA section to be included in the response all the time.
I realized I have no chance with DataContractSerializer.
So I have tried to mark my operation with [XmlSerializerFormat] and implement IXmlSerializable in the response class. I see that my serialization code is invoked but then it anyway does not work.
I am pretty sure now that WCF somehow analyzes the contents of the response and forces chars escaping there in a brutal way, ignoring my CDATA.
Maybe I should go further and try some custom behavior implementation. Have u got any idea ?
Tnx in advance.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I don't exactly know if this helps, but I had a somewhat similar issue, where I needed to pass-through a JSON response from another service.
Since WCF apparently escapes quotes and other characters, which obviously was unwanted behavior in my case, I needed to simply ignore any help from WCF.
What I did was change my response type to System.ServiceModel.Channels.Message
and then create a plain text message with System.ServiceModel.Web.WebOperationContext.Current.CreateTextResponse(responseText)
That did the trick! My message is now not interpreted by WCF, and my JSON response is unaltered.
More information here: http://msdn.microsoft.com/en-us/library/system.servicemodel.web.weboperationcontext.aspx