如何从WCF服务启动进程?

时间:2013-10-27 17:18:48

标签: c# wcf

我想从我的客户端Winforms应用程序运行一个进程,在我的情况下,客户端要求服务器在服务器的机器上创建一个新进程:

public void RunEXE()
{
    var processInfo = new ProcessStartInfo(@"D:\MyFile.exe")
    {
        CreateNoWindow = true,
        UseShellExecute = false
    };
    Process proc;

    if ((proc = Process.Start(processInfo)) == null)
    {
        throw new InvalidOperationException("??");
    }

    proc.WaitForExit();
    int exitCode = proc.ExitCode;
    proc.Close();
}

即使我尝试在本地计算机上运行此服务,也没有任何反应。 其他操作如update,receive string在本地和远程计算机上都可以正常工作。

服务器app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <system.web>
    <compilation debug="true"/>
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <bindings />
    <client />
    <services>
      <service name="WCFServiceHosting.MyService">
        <endpoint name="ServiceHttpEndPoint" address="" binding="basicHttpBinding" contract="WCFServiceHosting.IParametersXMLService">
        </endpoint>
        <endpoint name="ServiceMexEndPoint" address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://0.0.0.0:8733/MyService/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the value below to false before deployment -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="True"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

0 个答案:

没有答案