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

时间:2013-01-08 16:17:21

标签: android tridion tridion-2011

我正在开发一款用于连接Tridion 2011 SP1核心服务的Android应用。 到目前为止,我已经使用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");
  }
}

获得ApiVersion

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

1 个答案:

答案 0 :(得分:1)

弗兰克,

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

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

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

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

我创建了一个c#REST服务,位于Android应用程序和核心服务之间。

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

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

我已经让应用程序可以对Tridion进行身份验证,选择一个发布,然后以动态布局呈现的组件可以进行更新/保存/发布。

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

在初始测试中,这种方法在Android设备上看起来相当光滑。

相关问题