无法从Android客户端连接到Tridion Core Service

All*_*ane 9 android tridion tridion-2011

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

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

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

ReflectionHelper*java.lang.NoSuchFieldException:GetApiVersionResult.

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

有趣的是,如果我将代码作为java应用程序运行,那么使用wsimport存根就可以了.

任何帮助赞赏.这里有一个代码片段供参考:

要连接到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");
  }
}
Run Code Online (Sandbox Code Playgroud)

获得ApiVersion

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

小智 1

坦率,

由于几个原因这是不可能的。

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

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

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

我创建了 ac# REST 服务来位于 android 应用程序和核心服务之间。

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

其次,REST 服务与 CMS/CoreService 位于同一服务器上,因此通信速度更快,您可以更轻松地从 Android 应用程序发出 REST 请求。

我已经让应用程序达到了这样的程度,您可以向 Tridion 进行身份验证、选择出版物以及随后在动态布局中呈现的组件,以供更新/保存/发布。

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

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