我有一个窗口服务service1。 service1正在运行一个进程。我在webservice中调用了这个窗口服务。但它不允许在从webservice调用service1时启动该进程。 请找到以下代码。
服务1
namespace ContinuousIntegration
{
[ServiceContract]
public interface IContIntegService
{
[OperationContract]
string Execute(string Component);
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
// You can add XSD files into the project. After building the project, you can directly use the data types defined there, with the namespace "ContinuousIntegration.ContractType".
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
public class ContIntegService : IContIntegService
{
public string Execute(string component)
{
if(component == "Verification")
{
string exeFileName = string.Empty;
string workingDirectory = string.Empty;
string ServerArguments = string.Empty;
string moderatorPath = string.Empty;
string output = string.Empty;
workingDirectory = Path.GetDirectoryName(moderatorPath); ;
exeFileName = Path.GetFileName(moderatorPath);
ServerArguments = string.Concat("-c", " ", "TC", " ", "-r", " ", reportpath);
P = new Process();
try
{
if (P != null)
{
P.StartInfo.WorkingDirectory = workingDirectory;
P.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
P.StartInfo.FileName = exeFileName;
P.StartInfo.Arguments = ServerArguments;
P.StartInfo.CreateNoWindow = true;
runStatus = P.Start();
P.WaitForExit(5000);
while (!File.Exists(reportpath + "\\" + "TestCaseAll.html"))
{
Thread.Sleep(1000);
}
output = "Completed";
}
}
catch (Exception ex)
{
string msg = ex.Message;
runStatus = false;
}
runStatus = true;
return output;
}
}
}
的WebService
public string ExecuteWindowService(string component)
{
string result = string.Empty;
ServiceReference1.ContIntegServiceClient myService = new ServiceReference1.ContIntegServiceClient("NetTcpBinding_IContIntegService");
myService.Endpoint.Binding.SendTimeout = TimeSpan.MaxValue;
myService.Endpoint.Binding.ReceiveTimeout = TimeSpan.MaxValue;
myService.Endpoint.Binding.OpenTimeout = TimeSpan.MaxValue;
myService.Endpoint.Binding.CloseTimeout = TimeSpan.MaxValue;
result = myService.Execute(component);
myService.Close();
return result;
}