【发布时间】:2018-10-24 22:41:39
【问题描述】:
当我尝试将 XML 提交到发布在服务器上的 Web 服务时,我收到了这个错误。当我从 Visual Studio 的调试模式提交时,它工作正常。我真的坚持这一点。任何帮助是极大的赞赏。谢谢
XML
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthUser xmlns="http://xxx.bbb.com/">
<ClientID>xxx</ClientID>
<Username>xxx</Username>
<Password>xxx</Password>
</AuthUser>
</soap:Header>
<soap:Body>
<InsertSecure xmlns="http://xxx.bbb.com/">
<orderXml>
<![CDATA[
<Root>
<County>Dorset</County>
</Root>
]]>
</orderXml>
</InsertSecure>
</soap:Body>
</soap:Envelope>
这是提交 XML 的 C# 代码
[WebMethod(Description = "Use this web service to submit new work orders. This needs authentication")]
[SoapHeader("User", Required = true)]
public XmlDocument InsertSecure(string orderXml)
{
if (User != null) //check whether the credentials are present
{
if (User.IsValid()) // check if the user is valid
{
try
{
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(orderXml);
return createXML(xdoc);
}
catch (Exception ex)
{
}
}
else
{
XmlDocument xAuthDeniedDoc = new XmlDocument();
StringBuilder sb = new StringBuilder();
sb.Append("<?xml version='1.0' encoding='utf-8' ?>");
sb.Append("<DocumentElement>");
sb.Append("<Response>Unauthorized Access");
sb.Append("</Response>");
sb.Append("</DocumentElement>");
xAuthDeniedDoc.LoadXml(sb.ToString());
return xAuthDeniedDoc;
}
}
}
创建 XML 方法
private XmlDocument createXML(XmlDocument xdoc)
{
try
{
string directory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
string filePath = directory + "WebServiceXML\\";
string dateStimeStamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
string fileName = "WorksOrderXML-" + dateStimeStamp + ".xml";
xdoc.Save(filePath + fileName);
XmlDocument xSucessDoc = new XmlDocument();
StringBuilder sb = new StringBuilder();
sb.Append("<?xml version='1.0' encoding='utf-8' ?>");
sb.Append("<DocumentElement>");
sb.Append("<SuccessResponse>Order Received Successfully");
sb.Append("</SuccessResponse>");
sb.Append("</DocumentElement>");
xSucessDoc.LoadXml(sb.ToString());
return xSucessDoc;
}
catch(Exception ex)
{
}
}
错误
<faultcode>soap:Server</faultcode>
<faultstring>System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Xml.XmlException: 'an' is an unexpected token. The expected token is '='. Line 1, position 93.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ParseAttributes()
at System.Xml.XmlTextReaderImpl.ParseElement()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.LoadXml(String xml)
at Stonewater.StonewaterInsertSecure(String orderXml)
--- End of inner exception stack trace ---</faultstring>
【问题讨论】:
-
请将full和complete错误信息复制粘贴到问题的body中。
-
我收到这个错误...“这个”错误?请显示错误!
-
上面的
xml代码是产生错误的唯一代码吗?我猜还有c#代码? -
如果您能提供minimal reproducible example,我们可以复制并粘贴到本地以重现问题,那就太好了。
-
我的意思是你只提供了一半的故事。该错误告诉您在解释您传入的
xml时出现问题,特别是在存在值为an 的字符串的情况下。这显然不包括在您提供给我们以帮助解决问题的内容中。
标签: c# xml web-services