wcf forces chars escaping in response

故事扮演 提交于 2019-12-08 02:18:23

问题



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



来源:https://stackoverflow.com/questions/3360895/wcf-forces-chars-escaping-in-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!