防止 WCF 在响应中编码字符串? [英] Prevent WCF from encoding strings in response?

查看:24
本文介绍了防止 WCF 在响应中编码字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以覆盖 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.com">
  <HttpPostResult>
    &lt;STAT xmlns:xsi=&quot;http://www.w3.org/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.com">
  <HttpPostResult>
    <STAT xmlns:xsi="http://www.w3.org/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屋!

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