获取响应XML失败,包括连接第三方Web服务的中文字符 [英] Getting failure in getting response XML include Chinese char on connecting third-party Webservice
问题描述
我当前的项目需要连接第三方WebService来获取信息.但是,如果响应XML包含中文单词,则将其放置在reference.cs中的invoke()中,所以我认为这是字符集问题.而且WebService已经在不同的网站中使用, 而且我无法触摸网络服务代码.请帮忙,让我知道是否有解决此问题的想法.
My current project require connect third-party WebService to get information. But throw in invoke() where located in reference.cs if the response XML contain chinese words, so I think this is charset problem. And the WebService already use in different website, and I can't touch the webservice code. Please help and let me know if there is any idea to fix the problem.
System.InvalidOperationException: There is an error in XML document (1, 237329). ---> System.Xml.XmlException: Unexpected end of file while parsing Name has occurred. Line 1, position 237329.
2 at System.Xml.XmlTextReaderImpl.Throw(Exception e)
3 at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
4 at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String arg)
5 at System.Xml.XmlTextReaderImpl.ParseQName(Boolean isQName, Int32 startOffset, Int32& colonPos)
6 at System.Xml.XmlTextReaderImpl.ThrowTagMismatch(NodeData startTag)
7 at System.Xml.XmlTextReaderImpl.ParseEndElement()
8 at System.Xml.XmlTextReaderImpl.ParseElementContent()
9 at System.Xml.XmlTextReaderImpl.Read()
10 at System.Xml.XmlTextReader.Read()
11 at System.Xml.XmlReader.ReadElementString()
12 at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderFareBookRequest.Read3_Item()
13 at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer3.Deserialize(XmlSerializationReader reader)
14 at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
15 --- End of inner exception stack trace ---
16 at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
17 at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
18 at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
19 at MobileGateway.WebAPI.BisTalk.FareBookRequest.DoEndGetAvailabilityFare(String Token) in D:\development\Priceline_mobile_gateway\trunk\MobileGateway.WebAPI\Web References\BisTalk\Reference.cs:line 214
開新視窗(view plain) | 列印(print) | ?
响应XML示例:
<?xml version="1.0" encoding="UTF-8"?><CUSTOMER xmlns:tx="urn:pricelineretail-message">
<REMARKS_ODS><REMARKS_OD><REMARKS_ID>1606</REMARKS_ID><LANG_ID>2 </LANG_ID><REMARKS_TXT>價格已包括</REMARKS_TXT><SEARCH_TYPE>A</SEARCH_TYPE><CARRIER_CODE>KA</CARRIER_CODE><MSG_TYPE>R</MSG_TYPE></REMARKS_OD><REMARKS_OD><REMARKS_ID>1603</REMARKS_ID><LANG_ID>2 </LANG_ID><REMARKS_TXT>價格已包括</REMARKS_TXT><SEARCH_TYPE>E</SEARCH_TYPE><CARRIER_CODE>CX</CARRIER_CODE><MSG_TYPE>R</MSG_TYPE></REMARKS_OD></REMARKS_ODS>
推荐答案
汉字是UNICODE,并且您正在使用编码 = " UTF -8". 您的属性值必须用双引号引起来.XLM字符集显示在下面的网页上
Chinese character are UNICODE and you are using encoding="UTF-8". Your attributes values need to be in double quotes. XLM character set is shown on the webpage below
http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
这篇关于获取响应XML失败,包括连接第三方Web服务的中文字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!