XML文档中的非法字符的ASP.NET Web服务 [英] Illegal characters in XML document in ASP.NET Web Service

查看:147
本文介绍了XML文档中的非法字符的ASP.NET Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要问和回答我的问题,我希望没有人心中,但我想这可能是有用的其他人。

I'm going to ask and answer my own question, I hope nobody minds but I thought this might be useful to other people.

如果您设置一个ASP.NET Web服务,返回包含对象中SOAP XML序列化和客户端试图反序列化XML后无效XML的一个会抛出异常的字符对象。

If you setup a ASP.NET Web Service that returns objects that contain characters that are invalid for XML an exception will be thrown after the object is serialized in to SOAP xml and the client attempts to deserialize that xml.

你如何解决这个问题?

推荐答案

要解决这个问题我生成了我的web服务与应用Wsdl.exe用是.NET的一部分的类文件。这是简单的做,在命令提示符下直接输入 Wsdl.exe用<路径web服务>

To fix this I generated the class file for my webservice with the wsdl.exe application that is part of .NET. This is straight forward to do, at a command prompt just type wsdl.exe <path to webservice>

在所生成我重载方法

protected XmlReader GetReaderForMessage(SoapClientMessage message, int bufferSize)

像这样

protected override XmlReader GetReaderForMessage(SoapClientMessage message, int bufferSize)
{
    XmlReaderSettings settings = new XmlReaderSettings();
    settings.CheckCharacters = false;
    return XmlTextReader.Create(message.Stream, settings);
}

这告诉XmlTextReader的忽略它正在读取XML文件的有效性。没有理由说我不在乎,如果XML是有效与否时,我只是要立即反序列化。

This tells the XmlTextReader to ignore the validity of the XML file it is reading. There's no reason that I care if the xml is valid or not when I'm just going to immediately deserialize it.

希望这可以帮助别人同样的问题在那里!

Hope this helps someone with the same problem out there!

这篇关于XML文档中的非法字符的ASP.NET Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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