gpt4 book ai didi

c# - XML 文档中存在错误...调用 Web 服务时

转载 作者:数据小太阳 更新时间:2023-10-29 02:27:54 32 4
gpt4 key购买 nike

我已经创建了一个 Web 服务和一个函数,它应该返回从一个普遍的数据库中检索到的 11000 条记录的列表

这是我在网络服务中的功能。

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class BBI : System.Web.Services.WebService
{
[WebMethod]
public List<myObject> getAll()
{
List<myObject> result = new List<myObject>();
PsqlConnection conn = new PsqlConnection("Host=soemthing;Port=something;Database=something;Encoding=IBM861");
conn.Open();
string strSql = "select 0, 1, 2, 3, 4, 5 from something";
PsqlCommand DBCmd = new PsqlCommand(strSql, conn);
PsqlDataReader myDataReader;
myDataReader = DBCmd.ExecuteReader();
while (myDataReader.Read())
{
myObject b = new myObject();
b.0 = Convert.ToInt32(myDataReader[0].ToString());
b.1 = myDataReader[1].ToString();
b.2 = myDataReader[2].ToString();
b.3 = myDataReader[3].ToString();
b.4 = myDataReader[4].ToString();
b.5 = myDataReader[5].ToString();
result.Add(b);
}
conn.Close();
myDataReader.Close();
return result;
}
}

然后我在我的客户端程序中添加对此 Web 服务的 Web 引用并调用引用 BBI。然后我调用 getAll 函数并得到错误:XML 文档 (1, 63432) 中存在错误。

public List<BBI.myObject> getAll()
{
BBI.BBI bbi = new BBI.BBI();

List<BBI.myObject> allBooks = bbi.getAll().OfType<BBI.myObject>().ToList();
return allBooks;
}

这里是完整的异常细节

System.InvalidOperationException was unhandled by user code
Message=There is an error in XML document (1, 71897).
Source=System.Xml
StackTrace:
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at BBI.BBI.getAllBooks() in c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\vefur\73db60db\a4ee31dd\App_WebReferences.jl1r8jv6.0.cs:line 252
at webServiceFuncions.getAllBooks() in c:\Documents and Settings\forritari\Desktop\Vefur - Nýr\BBI\trunk\Vefur\App_Code\webServiceFuncions.cs:line 59
InnerException: System.Xml.XmlException
Message='', hexadecimal value 0x01, is an invalid character. Line 1, position 71897.
Source=System.Xml
LineNumber=1
LinePosition=71897
SourceUri=""
StackTrace:
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String[] args)
at System.Xml.XmlTextReaderImpl.ParseNumericCharRefInline(Int32 startPos, Boolean expand, StringBuilder internalSubsetBuilder, Int32& charCount, EntityType& entityType)
at System.Xml.XmlTextReaderImpl.ParseCharRefInline(Int32 startPos, Int32& charCount, EntityType& entityType)
at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)
at System.Xml.XmlTextReaderImpl.ParseText()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlReader.ReadElementString()
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderBBI.Read2_Book(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderBBI.Read20_getAllBooksResponse()
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer35.Deserialize(XmlSerializationReader reader)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
InnerException:

数据库记录包含各种奇怪的符号,例如¤rmann Kr。 EinarssonTv” ‘fint∼ri

有人能看出我在这里做错了什么吗?

最佳答案

使用 SoapUI 使用服务,发送请求,然后查看返回的内容。如果它在 SoapUI 中看起来不错,那么您就知道它被正确地从数据库读取和馈送,问题可能出在您的客户端,可能与编码有关。如果它在 SoapUI 中看起来不对,那是服务器端或数据库中的数据有问题。

像 SoapUI 和 Fiddler 这样的工具非常适合中间人检查这类事情。当您不确定是服务器还是客户端出现问题时,将问题减半总是有帮助的。

关于c# - XML 文档中存在错误...调用 Web 服务时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4554178/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com