C# 从另一个.exe调用.exe以运行Web服务
我尝试了几种类型的示例,从另一个带有参数的.exe文件调用.exe文件,以 运行“web服务”,但有时我会遇到“500–内部服务器错误异常”C# 从另一个.exe调用.exe以运行Web服务,c#,cmd,C#,Cmd,我尝试了几种类型的示例,从另一个带有参数的.exe文件调用.exe文件,以 运行“web服务”,但有时我会遇到“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 fro
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次,当我从8个批处理文件逐个调用第二个.EXE时,没有问题
现在我正在尝试从button click events中的批处理文件的第一个.Exe instad中逐个运行此服务,然后当第一个事件完成第二个事件启动时,我收到500错误
我做错了什么,请给我一些建议。替换这行:
startInfo.FileName = @"C:\WebserviceClient.exe";
ThreadPool.QueueUserWorkItem(delegate { Process.Start("C:\\WebserviceClient.exe"); });
这一行:
startInfo.FileName = @"C:\WebserviceClient.exe";
ThreadPool.QueueUserWorkItem(delegate { Process.Start("C:\\WebserviceClient.exe"); });
另一种方法是:
尝试添加Process.WaitForExit;在您的流程之后。StartstartInfo;哦,是的。毫无疑问,这个过程似乎不是以单个进程结束的,运行了3次。我不太确定,我正在测试我的应用程序,2次得到相同的结果,3次执行。仍在测试中,无论如何感谢您的解决方案。大家好,我的系统运行良好。问题是,当我运行该服务时,所有相关记录都会插入到我的日志表中,但一段时间后,这些记录也会第二次插入,并且会在我的日志表中不断插入重复记录。如何停止重复插入。我建议发布另一个包含详细信息的问题。