«an» - неожиданный знак. Ожидаемый токен '=' - PullRequest
0 голосов
/ 15 мая 2018

Я получаю эту ошибку, когда пытаюсь отправить XML в веб-службу, опубликованную на сервере. Когда я отправляю из режима отладки в 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>

Это код C # для отправки XML

[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)
    {
    }

}

Error

<faultcode>soap:Server</faultcode>
            <faultstring>System.Web.Services.Protocols.SoapException: Server was unable to process request. ---&gt; 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>

1 Ответ

0 голосов
/ 15 мая 2018

Фактическая ошибка была в расположении файла. Вместо следующего:

string directory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;

string filePath = directory + "WebServiceXML\\";

Я использовал

string filePath = @"C:\WebServiceXML\";

Спасибо всем.Ваш вклад был высоко оценен

...