繁体   English   中英

从C#客户端RPC到基于Java的Google App Engine

[英]RPC to java based Google App Engine from C# Client

从C#客户端调用基于Java的Google App Engine服务器时遇到很多问题

这是我的客户代码的样子:

 // C# Client
static void Main(string[] args)
{
  const string URL = "http://localhost:8888/googlewebapptest7/greet";
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
  request.Method = "POST";
  request.ContentType = "text/x-gwt-rpc; charset=utf-8";
  string content = "<?xml version='1.0'?><methodCall><methodName>greetServlet.GetName</methodName><params></params></methodCall>";
  byte[] contentBytes = UTF8Encoding.UTF8.GetBytes(content);
  request.ContentLength = contentBytes.Length;
  using (Stream stream = request.GetRequestStream())
  {
    stream.Write(contentBytes, 0, contentBytes.Length);
  }

  // get response
  WebResponse response = request.GetResponse();
  using (Stream responseStream = response.GetResponseStream())
  {
    string res = new StreamReader(responseStream).ReadToEnd();

    Console.WriteLine("response from server:");
    Console.WriteLine(res);
    Console.ReadKey();
  }     

该服务器基本上是Google默认的Web项目,带有其他方法:

public String GetName() { return "HI!"; }

已添加到GreetingServiceImpl。

每次运行客户端时,都会从服务器收到以下异常: An IncompatibleRemoteServiceException was thrown while processing this call. com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException: This application is out of date, please click the refresh button on your browser. ( Malformed or old RPC message received - expecting version 5 ) An IncompatibleRemoteServiceException was thrown while processing this call. com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException: This application is out of date, please click the refresh button on your browser. ( Malformed or old RPC message received - expecting version 5 )

我想将其保留在简单的HTTP请求中。

知道发生了什么吗?

正如Nick指出的那样,您正在尝试模仿GWT的RPC格式。 我也尝试过:)

然后我采取了不同的方法。 我使用Google协议缓冲区作为HTTP(S)上的编码器/解码器。

我的项目之一是用C#编写的桌面应用程序。 服务器端也是C#.Net。 自然地,我们使用WCF作为运输工具。

您可以将协议缓冲区插入WCF传输。 对于C#客户端和Java服务器,您将具有相同的接口配置。 非常方便

当我不太忙于工作时,我将使用代码示例更新此答案。

我从来没有找到在Google App Engine上使用基于XML的RPC的好方法。 相反,我通过教程找到了这个出色的JSON库:

http://werxltd.com/wp/portfolio/json-rpc/simple-java-json-rpc/

效果很好!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM