防止 WCF 在响应中编码字符串?

编程入门 行业动态 更新时间:2024-10-23 18:26:00
本文介绍了防止 WCF 在响应中编码字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

是否可以覆盖 WCF 中的设置以防止响应字符串中的 HTML 编码字符?

Is it possible to override a setting in WCF to prevent HTML encoding characters in a response string?

我有一个由第三方工具通过 SOAP 调用调用的简单服务.响应对象有一个由包含 XML 的字符串组成的属性.当 WCF 打包响应时,它变成:

I have a simple service that is called by a third party tool via a SOAP call. The response object has a single property consisting of a string which will contain XML. When WCF packages up the response, it becomes:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<HttpPostResponse xmlns="http://ws.lenderprise">
  <HttpPostResult>
    &lt;STAT xmlns:xsi=&quot;http://www.w3/2001/XMLSchema-instance&quot; &gt;
      &lt;RESPONSE Attr1=&quot;1&quot; 
             Attr2=&quot;ABC&quot; 
      &lt;/RESPONSE&gt;
    &lt;/STAT&gt;
  </HttpPostResult>
</HttpPostResponse>

是否可以不对包含的字符串进行编码?

Is it possible to not have the contained string encoded?

<?xml version="1.0" encoding="ISO-8859-1" ?>
<HttpPostResponse xmlns="http://ws.lenderprise">
  <HttpPostResult>
    <STAT xmlns:xsi="http://www.w3/2001/XMLSchema-instance" >
      <RESPONSE Attr1="1" 
             Attr2="ABC"> 
      </RESPONSE>
    </STAT>
  </HttpPostResult>
</HttpPostResponse>

我理解这仍然让我不得不确保处理任何嵌入的字符,并且这仍然意味着接收端的考虑.

I understand this still leaves me on the hook for ensuring any embedded characters are handled and that this still implies considerations on the receiving end.

推荐答案

如果你想返回 XML 而不是字符串,那么你可以使用 XElementXmlElement作为您的返回类型.在这种情况下,它不会被编码为字符串.

If you want to return XML instead of a string, then you can use either XElement or XmlElement as your return type. In that case it will not be encoded as a string would.

这篇关于防止 WCF 在响应中编码字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 19:20:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141160.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   WCF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!