C# 如何从WCF Rest方法返回自定义xml?
我们使用自定义序列化模式对对象进行xml序列化。我有一个用WCF服务Tempalte编写的WCF REST服务。我想从此方法返回自定义XML,但当我将返回设置为字符串时,我得到的是:C# 如何从WCF Rest方法返回自定义xml?,c#,.net,wcf,rest,serialization,C#,.net,Wcf,Rest,Serialization,我们使用自定义序列化模式对对象进行xml序列化。我有一个用WCF服务Tempalte编写的WCF REST服务。我想从此方法返回自定义XML,但当我将返回设置为字符串时,我得到的是: <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"> <?xml version="1.0" encoding="utf-16"?><ReportResponse>
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
<?xml version="1.0" encoding="utf-16"?><ReportResponse><Status>Success</Status><Url>http://pictor.blob.core.windows.net/pictor/ServiceTest.pdf</Url><ReportRequestId>00000000-0000-0000-0000-000000000000</ReportRequestId></ReportResponse>
</string>
?xml version=“1.0”encoding=“utf-16”?报告响应启动成功/状态Urlhttp://pictor.blob.core.windows.net/pictor/ServiceTest.pdf/UrlReportRequestId00000000-0000-0000-0000-000000000000/ReportRequestId/ReportResponse
正如您所看到的,我的xml被包装在一个html编码的字符串中。。如何返回适当的xml响应?使用XElement作为响应类型可以返回我选择的任何xml。
这个答案归功于@Mark Gravell 您是否尝试过返回类似于
XmlDocument
或XElement
的内容?此内容的可能重复项似乎是重复项或类似项。这里的关键是XElement。谢谢你,马克!