【问题标题】:Unable to connect to Tridion Core Service from an Android client无法从 Android 客户端连接到 Tridion 核心服务
【发布时间】:2012-12-22 13:32:44
【问题描述】:

我正在开发一个用于连接到 Tridion 2011 SP1 核心服务的 Android 应用程序。 到目前为止,我已经使用 wsclient 从核心服务 wsdl 创建了 Android WS Stub。

导入了那些允许访问所有核心服务方法的存根。

我现在可以通过 Android 应用程序向 Tridion 进行身份验证,但是一旦我尝试执行最基本的 Web 服务调用,例如 getApiVersion(),我就会收到错误消息:

ReflectionHelper*java.lang.NoSuchFieldException: GetApiVersionResult.

我想知道有没有其他人设法创建一个与核心服务通信的 java android 应用程序?

有趣的是,如果我将代码作为 java 应用程序运行,使用 wsimport stubs 一切都很好。

任何帮助表示赞赏。这里有一个代码 sn-p 供参考:

要连接到 Tridion:

class TridionConnect extends AsyncTask<String, Integer, String> { 
  // Called to initiate the background activity

  @Override
  protected String doInBackground(String... statuses) {  
    try {
      Authenticator.setDefault(new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication("username", "password".toCharArray());
        }
      });

      url = new URL("http://tridion-server/webservices/CoreService2011.svc?wsdl");

      System.out.println(String.format("Get Service"));
      service = new CoreService2011();
      System.out.println(String.format("Get Client"));

      client = service.getBasicHttp();

      return "Authenticated To Tridion";
    } catch (Exception e) {
      Log.e("Authentication failure", e.toString());
      e.printStackTrace();
      return "Failed to authenticate";
    }
  }

  // Called when there's a status to be updated
  @Override
  protected void onProgressUpdate(Integer... values) {
    super.onProgressUpdate(values);
    // Not used in this case
  }

  // Called once the background activity has completed
  @Override
  protected void onPostExecute(String result) { // 
    Toast.makeText(FullscreenActivity.this, result, Toast.LENGTH_LONG).show();  
    area.setText("Authenticated to Tridion OK");
  }
}

获取 ApiVersion

client.getApiVersion();
UserData currentUser = client.getCurrentUser();
System.out.println(String.format("'%s' %s", currentUser.getTitle(), currentUser.getId()));

【问题讨论】:

  • 嗨艾伦,一般来说最好将整个异常传递给Log.e,而不仅仅是toStringLog.e("TridionConnect", "Authentication Failure", e);
  • 我刚刚看到您已经说过代码在常规程序中运行良好。在那种情况下,它可能是真正的 JVM/JRE 和 Dalvik 之间的差异。但如果不重现您的问题,我无法确定。
  • 我现在得出的结论是,如上所述,这是不可能的。我现在正在研究另一种解决方案。
  • 您是否也发现了为什么这是不可能的。如果将来有人想尝试相同的方法,那可能会有所帮助,因为……事情会发生变化。顺便说一句:我之前完全忘了说,但我从 Android 客户端连接到 Tridion 内容交付 (OData) 服务没有问题。它为在本机应用程序中使用 Web 内容提供了一个很好的用例。
  • 问得好,您是否有兴趣提交Area 51 Tridion specific proposal。如果有时间,请使用同一个 SO 帐户注册。

标签: android tridion tridion-2011


【解决方案1】:

弗兰克,

这不可能有几个原因。

如果您使用 wsimport 创建 coreservice 代理,它将使用 JRE 中存在的 javax 库。然而,Dalvik 只实现了 javax 库的一个子集,这意味着这种方法在 Android 环境中是不可能的。

然后我查看了用于创建代理的 Ksoap2 工具。这似乎工作正常,尽管它确实创建了一个代理,但它与核心服务不匹配,所以我无法进行身份验证。除了检查 JRE 代理 v Ksoap2 代理之外,我没有进一步了解这种方法。它们完全不同。

此时我退后一步,喝了杯茶,重新设计了方法。

我创建了一个 C# REST 服务,位于 android 应用和核心服务之间。

这种方法看起来有点复杂,但它提供了很多优势。很多繁琐的工作都可以在 REST 服务中完成,这将比平板电脑或手机上的类似代码快得多。

其次,REST 服务与 CMS/CoreService 位于同一台服务器上,因此通信速度更快,您可以使来自 android 应用的 REST 请求更轻松。

我已经让应用程序达到了可以向 Tridion 进行身份验证、选择发布和组件的地步,然后这些组件会以动态布局呈现,以供更新/保存/发布。

这种方法的一大缺点是 REST 服务“应该”是无状态的,因此从表面上看,您必须针对每个请求对核心服务进行身份验证。当然我不这样做,但你必须想出一些替代方法 Oauth、共享秘密等。

在最初的测试中,这种方法在安卓设备上似乎相当流畅。

【讨论】:

  • 嗨,巴特,我致力于 51 区提案。当我们在 5.1 版本时,我开始了 Tridion 开发,唯一的资源是 tridion 论坛和支持部门。现在是时候为 Tridion 的所有事物提供公开可用的资源了。
  • 以上两位来自 Josanne Kane 的 cmets,实际上都是来自我的……我的妻子显然使用了我的笔记本电脑。顺便说一句,除非涉及烘焙,否则不要接受她的任何建议!
猜你喜欢
  • 2012-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-22
  • 2014-11-19
  • 2018-10-14
  • 2020-07-08
  • 1970-01-01
相关资源
最近更新 更多