开发者

wcf forces chars escaping in response

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 开发者_StackOverflow中文版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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜