wcf强制转义chars [英] wcf forces chars escaping in response

查看:179
本文介绍了wcf强制转义chars的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在WCF响应中返回未转义的html,因此我需要在响应中包含CDATA部分。


我意识到我没有机会使用DataContractSerializer。
所以我试图用[XmlSerializerFormat]标记我的操作,并在响应类中实现IXmlSerializable。我看到我的序列化代码被调用,但是无论如何,它不起作用。


我现在很确定,WCF以某种方式分析响应的内容,并强制以一种残酷的方式逃离那里的字符,忽略了我的CDATA。
也许我应该进一步去尝试一些自定义行为的实现。你有什么想法吗
Tnx提前。


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.

推荐答案

我不完全知道这是否有帮助,但我有一个类似的问题,我需要从另一个服务传递一个JSON响应。

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.

由于WCF显然会转义引号和其他字符,这在我的情况下显然是不需要的行为,所以我需要简单地忽略WCF的任何帮助。

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.

我所做的是将我的响应类型更改为 System.ServiceModel.Channels.Message 然后使用 System.ServiceModel.Web.WebOperationContext.Current.CreateTextResponse(responseText)创建纯文本消息

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)

这样做了!我的消息现在不被WCF解释,我的JSON响应没有改变。

That did the trick! My message is now not interpreted by WCF, and my JSON response is unaltered.

更多信息在这里: http://msdn.microsoft.com/en-us/library/system.servicemodel.web.weboperationcontext.aspx

这篇关于wcf强制转义chars的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆