我已尝试使用几种类型的示例从另一个带有参数的.exe文件中调用.exe文件 运行网络服务'但我得到了一些时间' 500 - 内部服务器错误异常'。
1. code in First .Exe(code for only for one event, i have 8 event like this to run in Button click)
dateTimePicker4.CustomFormat = "yyyy-MM-dd";
string frodate = dateTimePicker4.Value.Date.ToShortDateString();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\WebserviceClient.exe"; // this is the second .EXE file
startInfo.Arguments = "300000 supplier" + " " + frodate; // thesse are the 3 parameters
Process.Start(startInfo);
2. My second .Exe file receive these parameters and call the Web-Service like below
WebRequest webRequest = WebRequest.Create("http://My Server Path/epos/getproduct.asmx"); // this is web service in another location
HttpWebRequest httpRequest = (HttpWebRequest)webRequest;
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml; charset=utf-8";
httpRequest.Headers.Add("SOAPAction: http://tempuri.org/getCategory");
httpRequest.ProtocolVersion = HttpVersion.Version11;
httpRequest.Credentials = CredentialCache.DefaultCredentials;
Stream requestStream = httpRequest.GetRequestStream();
//Create Stream and Complete Request
StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.ASCII);
StringBuilder soapRequest = new StringBuilder("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
soapRequest.Append(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ");
soapRequest.Append("xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>");
soapRequest.Append("<getCategory xmlns=\"http://tempuri.org/\">");
soapRequest.Append("<inBranch>" + strParam + "</inBranch>");
soapRequest.Append("<dir>" + strParamDir + "</dir>");
soapRequest.Append("<modifyDateFrom>" + strModifyDateFrom + "</modifyDateFrom>");
soapRequest.Append("<modifyDateTo>" + strModifyDateTo + "</modifyDateTo>");
soapRequest.Append("</getCategory>");
soapRequest.Append("</soap:Body></soap:Envelope>");
streamWriter.Write(soapRequest.ToString());
streamWriter.Close();
//Get the Response
HttpWebResponse wr = (HttpWebResponse)httpRequest.GetResponse(); // here i am getting the ERROR
StreamReader srd = new StreamReader(wr.GetResponseStream());
string resulXmlFromWebService = srd.ReadToEnd();
//注意 - 当我从8个批处理文件中逐个调用第二个.EXE时,我必须使用不同的参数运行此服务8次,然后没有问题。
现在我正在尝试从按钮点击事件中的第一个.Exe批处理文件中逐个运行此服务,然后在第一个事件完成第二个事件开始时我收到500错误。
我做错了什么,请给我一些建议。
答案 0 :(得分:0)
替换此行:
startInfo.FileName = @"C:\WebserviceClient.exe";
这一行:
ThreadPool.QueueUserWorkItem(delegate { Process.Start("C:\\WebserviceClient.exe"); });
另一种方法如下:
public static void TestCommands()
{
var command = "WebserviceClient.exe";
ExecuteCommand(command, 5000);
var command = "WebserviceClient2.exe";
ExecuteCommand(command, 5000);
}
public static int ExecuteCommand(string command, int timeout)
{
var processInfo = new ProcessStartInfo(command)
{
CreateNoWindow = true,
UseShellExecute = false,
WorkingDirectory = @"C:\\",
};
var process = Process.Start(processInfo);
process.WaitForExit(timeout);
var exitCode = process.ExitCode;
process.Close();
return exitCode;
}