1

首先,对不起我糟糕的英语。我找到了这篇文章并关注它。 https://developers.google.com/appengine/articles/soap?hl=vi

它奏效了。现在我只想创建这样的服务器以在其他客户端中使用。可以吗?例如,当我将 HelloSOAPServerServlet 部署到 abc@appspot.com 并且当我想使用我的服务时,我只需将此 URL:abc@appspot.com/hellosoapserver?name=SOAP&arriving=true 粘贴到浏览器。我怎么能做这样的事情?因为我希望我的客户使用此服务的是 Andoird 电话。

4

2 回答 2

0

abc@appspot.com是一个电子邮件地址。您不能将 GAE 代码部署到它。

创建GAE 应用程序时,您必须选择一个唯一的应用程序名称,例如mysoap. 您的应用程序的 url 将是http://mysoap.appspot.com/.

将代码上传到它后,您可以在以下位置访问您的 SOAPhttp://mysoap.appspot.com/hellosoapserver?name=SOAP&arriving=true

于 2012-12-12T19:15:30.833 回答
0

你在那个例子中得到了它。

您在以下位置创建了 SOAP Web 服务:

在 Google App Engine 上构建 SOAP 服务器

然后您创建了一个从 Servlet 使用它的客户端:

使用 JAX-WS 在 Google App Engine 上构建 SOAP 客户端

现在您需要从您的 Android 应用程序中使用正确的参数值对该 URL 进行 HTTP 客户端调用。

使用http://developer.android.com/reference/java/net/HttpURLConnection.html提供的示例和 url 提供了您的示例

   URL url = new URL(" http://greeter-client.appspot.com/hellosoapclient?name=SOAP&arriving=true");
   HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
   try {
     InputStream in = new BufferedInputStream(urlConnection.getInputStream());
     readStream(in);
    finally {
     urlConnection.disconnect();
   }

readStream中,您可以从 GAE 托管的服务中读取响应

readStream 可以是这样的:

private static String readStream(InputStream is) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return sb.toString();
}
于 2012-12-12T19:21:56.477 回答