WCF 强制字符转义作为响应

发布于 2024-09-12 03:08:23 字数 288 浏览 0 评论 0原文


我想在 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光病人 2024-09-19 03:08:23

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

由于 WCF 显然转义了引号和其他字符,这在我的情况下显然是不需要的行为,因此我需要忽略 WCF 的任何帮助。

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

就成功了!现在,WCF 不会解释我的消息,并且我的 JSON 响应也不会改变。

更多信息请参见:http://msdn.microsoft.com /en-us/library/system.servicemodel.web.weboperationcontext.aspx

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文