服务器上的C#/ Web Service应用程序抛出奇怪的异常

时间:2010-02-11 19:44:25

标签: c# web-services soap

我们将ADP用于员工信息。我不得不创建一个小应用程序,调用一些ADP必须提取员工信息的Web服务。该应用程序是相当程序化的......在某种意义上,它不是真正的面向对象。基本上我会通过一些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)."

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

  

EventType 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上的“帮助和支持中心”。

我输入了一些console.writelines来查看它失败的地方......

以下是main的一个简单示例:

 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();

多数人失去了所有地狱(基本上它不起作用)。 EmpWorkInfo()只是一个从Web服务获取工作相关信息的函数(正如我所说,它在本地工作)。

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());
    }
}

这个函数代码是无关紧要的(它的丑陋,但不要让你烦恼,代码工作......)。我的问题是我甚至无法访问该函数的第一个console.writeline。在使用webservices时,我需要做些什么特别的事情吗?

修改

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

private static string logPath = Environment.CurrentDirectory + "\\log\\";

5 个答案:

答案 0 :(得分:1)

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

1)您可以在命令窗口(cmd.exe)中在目标服务器上运行此应用程序吗? 2)您是否正在使用ADP中安装在全局程序集缓存(GAC)中的任何程序集?在localmachine上运行“gacutil -l”以查看是否使用了安装在thr gac中的ADP中的任何程序集。如果是,则需要将这些安装到运行该应用程序的计算机上。

答案 1 :(得分:0)

logPath是否有反斜杠?无论哪种方式,您都应该使用Path.Combine,而不是字符串连接运算符(+)。

答案 2 :(得分:0)

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

答案 3 :(得分:0)

发现我需要在服务器上安装Microsoft.Web.Services3 dll。

答案 4 :(得分:0)

继续“feroze”回答;

如果你想弄清楚'加载依赖关系'是否会让你感到悲伤,我建议使用“FUSLOGVW.EXE”工具*(.Net的一部分)。当你运行它时,它会给你一个带有几个选项的小对话窗口。在某处创建目录(如“c:\ temp \ fusion_logs”),将FUSLOGVW的模式设置为“仅记录绑定失败”,“自定义位置 - > c:\ temp \ fusion_logs”。

现在重启您的应用程序并检查它是否失败。现在看看你的fusion_logs目录。这应该为您提供具有不同(目前可能只有1个)应用程序名称的子目录。在每个目录中,您将找到日志文件。这些日志文件包含“失败的程序集加载”以及谁(调用程序集)导致它们。

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

希望这有帮助,

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