我们使用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\\";