i have tried with several type of examples to call a .exe file from another .exe file with parameters to
run a 'web service',but i am getting some times '500 – Internal Server Error exception'.
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();
// NOTE-- i have to run this service 8 times with different parameters, when i call this second .EXE from 8 batch files one by one, then no issue.
now i am trying to Run this service from my First .Exe instad of Batch file one by one in button click events , then i am getting the 500 error when first event complete second event start.
what i am doing wrong,Please give me some suggestions.
Replace this line:
with this line:
Another way is the following: