从WCF调用python代码

时间:2017-07-03 13:27:14

标签: python-2.7 wcf

我需要将一个python代码作为WCF提供给另一个应用程序来访问它。 python代码由数据科学团队构建,无法更改它。我尝试将程序作为进程shell运行,但它给出了System.InvalidOperationException'例外。 我创建了与C#控制台应用程序相同的程序,它工作正常。问题是 一个。这是将python代码提供给另一个应用程序的正确方法(REST API不是一个选项)。 湾我的代码有什么问题。

public string ClassifyText(string value)
{
    string textoutput = "";

    string exeFileName = HttpContext.Current.Server.MapPath("~/python.exe");
    string argName = HttpContext.Current.Server.MapPath("~/predictionscript.py");

    ProcessStartInfo start = new ProcessStartInfo();
    start.FileName = exeFileName;
    start.Arguments = argName;
    start.UseShellExecute = false;
    start.RedirectStandardOutput = true;

    using (Process process = Process.Start(start))
    {
        using (StreamReader reader = process.StandardOutput)
        {
            string result = reader.ReadToEnd();
            textoutput = result;
        }
    }
    return textoutput;
}

0 个答案:

没有答案