代码之家  ›  专栏  ›  技术社区  ›  Grigoris Loukidis

调用moses上的转换方法作为使用xml-rpc的服务失败

  •  1
  • Grigoris Loukidis  · 技术社区  · 6 年前

    我面临一个异常,将moses(统计机器翻译)作为安装了xmlrpc的服务调用。我首先打开一个到摩西服务器的端口

    --Listening on port 8082
    

    但主要的问题是当我发送一个以xml作为主体参数的rest请求时。

    <methodCall>
    <methodName>translate</methodName>
    <params>
    <param>
    <value>
    <array>
    <data>
    <value>
    <array>
    <data>
    <value>
    <string>struct</string>
    </value>
    <value>
    <string>struct</string>
    </value>
    </data>
    </array>
    </value>
    </data>
    </array>
    </value>
    </param>
    </params>
    </methodCall>
    

    当我在 http://xxx.xxx.xxx.xxx:8082/RPC2

    我注意到端口上的服务失败,出现异常“在抛出'xmlrpc\u c::fault'实例后调用terminate” 流产的 “

    我认为主要的问题是xml的主体结构,但是我在web上找不到任何用于translate方法的文档。有什么建议吗?谢谢您。

    更新

    注意,如果我打开一个带有设置的端口

    --threads all
    

    我再也没有得到回应。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Grigoris Loukidis    6 年前

    一种工作方法,但可能不是最干净和最安全的,是调用Cython或Cython的Python客户端,因为在NuGET上不存在用于执行这项工作的库。

    ProcessStartInfo start = new ProcessStartInfo();
    
                start.FileName = "C:\\python\\python.exe";
    
                start.Arguments = $"C:\\python27\\client.py {word}";
    
                start.UseShellExecute = false; // Do not use OS shell
    
                start.CreateNoWindow = true; // We don't need new window
    
                start.RedirectStandardOutput = true; // Any output, generated by application will be redirected back
    
                start.RedirectStandardError = true; // Any error in standard output will be redirected back (for example exceptions)
    
                using (Process process = Process.Start(start))
                {
                    using (StreamReader reader = process.StandardOutput)
                    {
                        string stderr = process.StandardError.ReadToEnd(); // Here are the exceptions from our Python script
    
                        string output = process.StandardOutput.ReadToEnd();
    
                        string result = reader.ReadToEnd(); // Here is the result of StdOut(for example: print "test")
                    }
                }
    

    客户就是这样 client.py