我在 asp.net web api 中。在 API 方法中,我正在调用一个返回 XML 响应的外部 Web 服务。我不想反序列化它。我宁愿将它按原样发送给客户。最初,我将响应存储在XDocument对象中,但是当我的客户端指定application/xml为接受标头时,我看到以下异常
Type 'System.Xml.Linq.XDeclaration' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.
我该如何解决这个问题