代码之家  ›  专栏  ›  技术社区  ›  JonH

服务器上的C#/Webservice应用程序引发奇怪异常

  •  1
  • JonH  · 技术社区  · 16 年前

    我们使用ADP获取员工信息。我必须创建一个称为web服务的小应用程序,ADP必须提取员工信息。这个应用程序相当程序化。从某种意义上说,它不是真正面向对象的。基本上,我通过一些web服务来获取一般信息、工作信息、员工状态等。

    我将这些数据的大部分作为日志写入文本文件,这样我就可以确保一切正常工作。终于全部完成了,它在我的本地机器上运行得非常完美。我想我应该将整个结构复制到服务器上,然后使用windows调度程序来安排exe每晚(每天一次)运行。当它尝试运行该应用程序时,调用第一个web服务时,它看起来好像快死了。任务计划程序日志显示:

    ""ADP.job" (ADP.exe)
        Started 2/11/2010 2:14:34 PM
    "ADP.job" (ADP.exe)
        Finished 2/11/2010 2:14:38 PM
        Result: The task completed with an exit code of (e0434f4d)."
    

    所以我检查了事件查看器,它说:

    事件类型clr20r3、P1 adp.exe、P2 1.0.0.0、P3 4b745bb9、P4 adp、P5 1.0.0.0、P6 4b745bb9、P7 289、P8 2d、P9 system.io.filenotfoundexception、P10 NIL。

    有关更多信息,请参阅帮助和支持中心,网址为 http://go.microsoft.com/fwlink/events.asp

    我放了一些控制台,看看哪里出了问题。。。

    以下是一个简单的主要示例:

     static void Main(string[] args)
            {
                OpenTextFile();
    
                Console.WriteLine("About to process employee work information...");
                tw.WriteLine("About to process employee work information...");
                //work info service
                EmpWorkInfo();
             }
    

    以及opentextfile的内部:

      public static void OpenTextFile()
            {
                //used to log data
                String sLogName;
                Console.WriteLine("Inside of opentextfile");
                if (Directory.Exists(logPath))
                {
                    //directory exists
                }
                else
                {
                    Directory.CreateDirectory(logPath);
                }
                Console.WriteLine("Inside of opentextfile2");
                sLogName = "log_" + DateTime.Today.ToString("MM_dd_yyyy") + ".txt";
                tw = new StreamWriter(logPath + sLogName);
            }
    

    我看到服务器上的所有console.writelines,但一旦它从main中点击这一行:

    EmpWorkInfo();
    

    static void EmpWorkInfo()
    {
        Console.Writeline("THIS NEVER PRINTS!!!");
        SQLClass s=null;
        // Create the web service proxy client.
        GetEmployeeWorkInfoService oService = new GetEmployeeWorkInfoService();
        oService.Timeout = Int32.MaxValue;
        // Serialize the UsernameToken into XML.
        // Create the UsernameToken as defined in the WS-I secure profile.
        UsernameToken oUsernameToken = new UsernameToken(USERNAME, SECRET);
    
        System.Xml.XmlElement oSecurityHeaderXml =
        oUsernameToken.GetXml(new System.Xml.XmlDocument());
    
        ADP.GetEmployeeWorkInfoWebService.SecurityHeaderType oSecurityHeader = new ADP.GetEmployeeWorkInfoWebService.SecurityHeaderType();
        oSecurityHeader.Any = new System.Xml.XmlElement[] { oSecurityHeaderXml };
        oService.Security = oSecurityHeader;
    
        GetEmployeeWorkInfoRequestFilter oFilter = new GetEmployeeWorkInfoRequestFilter();
    
        //filter by thyssenkrupp company
        oFilter.Companies = new String[] { COMPANY_IDENTIFIER };
    
        GetEmployeeWorkInfoRequest oRequest = new GetEmployeeWorkInfoRequest();
        oRequest.Filter = oFilter;
    
        try
        {
            EmployeeWorkInfoType[] arPersonalInfo = oService.GetEmployeeWorkInfo(oRequest);
            try
            {
                s = new SQLClass();
            }
            catch (Exception e)
            {
                throw new System.Exception(e.Message.ToString());
            }
    
            for (int i = 0; i < arPersonalInfo.Length; i++)
            {
    
                String stID = arPersonalInfo[i].EmployeeKey.Identifier.EmployeeId;  //employee number
                String stEmailAddress = arPersonalInfo[i].WorkInfo.EmailAddress;    //employee email address (work)
                String stFax = arPersonalInfo[i].WorkInfo.Fax;                      //employee fax number
                DateTime dtHireDate = arPersonalInfo[i].WorkInfo.OriginalHireDate;
    
                String stPhone = arPersonalInfo[i].WorkInfo.Phone;                  //employee phone number
                String stWireless = arPersonalInfo[i].WorkInfo.Wireless;            //employee wireless number
                tw.WriteLine("Processing ID:" + stID + " Email Work: " + stEmailAddress + " Fax Work: " + stFax + " Hire Date: " + dtHireDate + " Phone Work: " + stPhone + " Wireless Work: " + stWireless + ".");
                Console.WriteLine("Processing ID:" + stID + " Email Work: " + stEmailAddress + " Fax Work: " + stFax + " Hire Date: " + dtHireDate + " Phone Work: " + stPhone + " Wireless Work: " + stWireless + ".");
                s.SetSQLCommand("dbo.ADP_uiEmployeeWorkInfo");
                s.AddSQLCmdParameter("@EmployeeNumber", System.Data.SqlDbType.VarChar, stID);
                s.AddSQLCmdParameter("@EmailAddress", System.Data.SqlDbType.VarChar, stEmailAddress);
                s.AddSQLCmdParameter("@Fax", System.Data.SqlDbType.VarChar, stFax);
                s.AddSQLCmdParameter("@HireDate", System.Data.SqlDbType.DateTime, dtHireDate);
                s.AddSQLCmdParameter("@Telephone", System.Data.SqlDbType.VarChar, stPhone);
                s.AddSQLCmdParameter("@Mobile", System.Data.SqlDbType.VarChar, stWireless);
                s.SQLExecuteNonQuery();                   
    
                Console.WriteLine("Processed ID:" + stID + " Email Work: " + stEmailAddress + " Fax Work: " + stFax + " Hire Date: " + dtHireDate + " Phone Work: " + stPhone + " Wireless Work: " + stWireless + ".");
                Console.WriteLine(Environment.NewLine);
            }
            s.CloseSQLDB();
            s.Dispose();
        }
        //catch any exception from adp side.
        catch (Exception e)
        {
            throw new System.Exception(e.Message.ToString());
        }
    }
    

    这个函数代码是不相关的(它很难看,但不要让它打扰你,代码可以工作…)。我的问题是我甚至无法访问该函数的第一个控制台.writeline。在使用Web服务时,我需要做什么特别的事情吗?

    编辑

    Logpath仅定义为main之外的静态字符串:

    private static string logPath = Environment.CurrentDirectory + "\\log\\";
    
    5 回复  |  直到 16 年前
        1
  •  1
  •   feroze    16 年前

    我怀疑您的应用程序无法加载该函数-EmpWorkInfo中引用的类型。

    1) 能否在commannd窗口(cmd.exe)中的目标服务器上运行此应用程序?

        2
  •  0
  •   Roger Lipscombe    16 年前

    logPath 后面有反斜杠吗?无论哪种方式,你都应该使用 Path.Combine

        3
  •  0
  •   Paul Manzotti    16 年前

    如果注释掉EmpWorkInfo()中除第一个Console.Writeline之外的所有代码,会发生什么?还没有写出来吗?

        4
  •  0
  •   JonH    16 年前

        5
  •  0
  •   Marvin Smit    16 年前

    继续“费罗兹”的回答;

    如果您想知道“加载依赖项”是否会让您感到悲伤,我建议您使用“FUSLOGVW.EXE”工具*(是.Net的一部分)。当您运行此程序时,它将为您提供一个带有一些选项的小对话框窗口。在某处创建一个目录(如“c:\temp\fusion_logs”),将FUSLOGVW的模式设置为“仅日志绑定失败”、“自定义位置->c:\temp\fusion\u日志”。

    他们可能会帮助你寻找一个有效的应用程序,

    编辑:找到原因后发布此消息。fuslogvw.exe会向您显示缺少的程序集。