【问题标题】:Web services return xml errorWeb 服务返回 xml 错误
【发布时间】:2011-05-05 03:25:16
【问题描述】:

突然间,对我的网络服务的所有调用都收到此错误:

2010-11-04 17:42:16,321 [9] ERROR ABCKiosk - System.InvalidOperationException: Response is not well-formed XML. ---> System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
   at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlTextReader.Read()
   at System.Xml.XmlReader.MoveToContent()
   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)
   --- End of inner exception stack trace ---
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at ABCKiosk.WebServices.Services.ActivityLog(String kioskID, String KTID, String activityType, Int32 errorCodeFromIncentOne, String msgFromIncentOne, DateTime kioskTime) in D:\SMS SHANE\KIOSK\ABCNC_Kiosk\Implementation\Source Code\ABCKioskClient\ABCKiosk\Web References\WebServices\Reference.cs:line 121
   at ABCKiosk.FrmMain.FrmMain_KeyUp(Object sender, KeyEventArgs e) in D:\SMS SHANE\KIOSK\ABCNC_Kiosk\Implementation\Source Code\ABCKioskClient\ABCKiosk\FrmMain.cs:line 110

在一切都很好之前:(有人知道问题出在哪里以及如何解决这个问题吗?

非常感谢!

更新 - 提供更多信息

这是我的一种网络方法:

[WebMethod(EnableSession = true)]
        public CommonResult ActivityLog(string kioskID, string KTID,
            string activityType, int errorCodeFromIncentOne, string msgFromIncentOne, DateTime kioskTime)
        {
            XMLParser parser = new XMLParser(Server.MapPath(Constant.XML_CONFIGURATION_FILE_PATH));
            CommonResult result = new CommonResult();
            try
            {
                AccountDAO accountDAO = new AccountDAO();
                ActivityLogDAO activityLogDAO = new ActivityLogDAO();
                KioskDAO kioskDAO = new KioskDAO();

                // check if this kiosk is existed
                if (!kioskDAO.IsKioskIDExisted(kioskID))
                {
                    result.ErrorCode = Constant.ERROR_CODE_KIOSKID_NOT_EXISTED;
                    result.Message = "abc";
                    return result;
                }

                // check if this KTID is existed
                if (!accountDAO.IsKTIDExisted(KTID))
                {
                    result.ErrorCode = Constant.ERROR_CODE_KTID;
                    result.Message = "abc";
                    return result;
                }

                // check if this customer already logged for today
                if (activityLogDAO.IsLoggedForToday(KTID, DateTime.Now))
                {
                    result.ErrorCode = Constant.ERROR_CODE_LOG_LIMIT;
                    result.Message = "abc";
                    return result;
                }

                // begin log this activity to database
                activityLogDAO.ActivityLog(KTID, kioskID, kioskTime);

                // return success
                result.ErrorCode = Constant.ERROR_CODE_SUCCESS;
                result.Message = "abc";
                return result;
            }
            catch (Exception e)
            {
                result.ErrorCode = Constant.ERROR_CODE_SYSTEM_ERROR;
                result.Message = "abc";
                return result;
            }
        }

更新

我尝试在本地运行 webmethod,检查了返回页面并在页面源中看到了这个:

<b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.



            <br><br>



            <b> Exception Details: </b>System.InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/ActivityLog'.<br><br>



            <b>Source Error:</b> <br><br>



            <table width=100% bgcolor="#ffffcc">

               <tr>

                  <td>

                      <code>



An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code>



                  </td>

               </tr>

            </table>



            <br>



            <b>Stack Trace:</b> <br><br>



            <table width=100% bgcolor="#ffffcc">

               <tr>

                  <td>

                      <code><pre>



[InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/ActivityLog'.]

   System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +405913

   System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +212

   System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +47

   System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +193

   System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +93

   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +155

</pre></code>

【问题讨论】:

  • 也许某个序列化步骤刚刚中断?请发布更多有关来回发送的数据的信息,甚至可能是 http 提要日志。
  • 如何获取http feed日志?我对 .Net 网络编程很陌生

标签: asp.net xml web-services exception


【解决方案1】:

我自己发现了这个错误,都是因为 Session_Start() 中的一行 Response.Write() 搞砸了一切:(

【讨论】:

    猜你喜欢
    • 2011-01-26
    • 1970-01-01
    • 2012-04-05
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    • 2011-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多