1
删除XML命名空间使用Web API和.NET的核心,当我返回XML结果我得到如下:从操作结果
<Test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Response>
<Status>0</Status>
</Response>
</Test>
如何删除的命名空间?
这里是我的startup.cs文件的一部分
services
.AddMvc(config =>
{
// Add XML Content Negotiation
config.RespectBrowserAcceptHeader = true;
config.InputFormatters.Add(new XmlSerializerInputFormatter());
config.OutputFormatters.Add(new XmlSerializerOutputFormatter(new XmlWriterSettings
{
OmitXmlDeclaration = true,
}));
})
.AddXmlDataContractSerializerFormatters()
.AddXmlSerializerFormatters()
.AddMvcOptions(opt => opt.FormatterMappings.SetMediaTypeMappingForFormat("xml", new MediaTypeHeaderValue("application/xml")));
你用RTM试过了吗?当RTM已经停用一段时间后仍然使用RC1/RC2听起来不是一个好计划。更好地迁移,也许它在RTM中得到修复 – Tseng
我应该提到我正在使用RTM。 – Mike
我的错误。我把它与一些从RTM中删除的东西混淆了。你删除了以前的OutputFormatters吗?即在添加之前调用'.OutputFormatters.Clear()'?我假设'.AddXmlSerializerFormatters()'已经添加了格式化程序,所以你的选项可能不会生效 – Tseng