从Android连接到Dynamics CRM 2016(本地) [英] Connect to Dynamics CRM 2016(On-Premise) from Android

查看:102
本文介绍了从Android连接到Dynamics CRM 2016(本地)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Android应用程序与Dynamics CRM 2015 Online和内部部署集成。
对于在线版本使用Web API将Android App连接到Dynamics CRM 的效果很好,但是OnPremise不支持ADAL依赖关系。
是否有任何资源可以显示在内部访问Microsoft CRM的基本步骤。
任何用于连接到REST端点的相同示例代码都会有所帮助。

I want to integrate Android application with Dynamics CRM 2015 Online and On-Premise.
For online version Connect Android App to Dynamics CRM using Web API this works fine, But ADAL dependency is not supported for OnPremise. Are there any resources which show the basic steps to access the Microsoft CRM on-premise. Any sample code around same for connecting to REST endpoint will be helpful.

推荐答案

使用本地ADAL:

public static String GetAdfs(String url) throws IOException,
            ParserConfigurationException, SAXException {
        URL WsdlURL = new URL(url
                + "/XrmServices/2011/Organization.svc?wsdl=wsdl0");
        HttpURLConnection rc = (HttpURLConnection) WsdlURL.openConnection();

    rc.setRequestMethod("GET");
    rc.setDoOutput(true);

    InputStreamReader read = new InputStreamReader(rc.getInputStream());
    StringBuilder sb = new StringBuilder();
    int ch = read.read();
    while (ch != -1) {
        sb.append((char) ch);
        ch = read.read();
    }
    String response = sb.toString();
    read.close();
    rc.disconnect();

    DocumentBuilderFactory builderFactory = DocumentBuilderFactory
            .newInstance();
    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    Document x = builder
            .parse(new ByteArrayInputStream(response.getBytes()));

    NodeList nodes = x.getElementsByTagName("ms-xrm:Identifier");
    if (nodes.getLength() == 0)
        return null;

    return nodes.item(0).getFirstChild().getTextContent()
            .replace("http://", "https://");
}


// ADAL init
 AuthenticationContext authenticationContext = new AuthenticationContext(LoginActivity.this, GetAdfs(url), false);


authenticationContext.acquireToken(context, domain, Constants.CLIENT_ID, Constants.REDIRECT_URL, "", PromptBehavior.Auto, "", callback);

private AuthenticationCallback<AuthenticationResult> callback = new AuthenticationCallback<AuthenticationResult>() {

    @Override
    public void onError(Exception exc) {
        ViewHelper.showToast(context, "Domain name or user not available in ms crm");

    }

    @Override
    public void onSuccess(AuthenticationResult result) {
        if (result == null || result.getAccessToken() == null || result.getAccessToken().isEmpty()) {
            Toast.makeText(context, "Token is Empty", Toast.LENGTH_SHORT).show();
        } else {
            Log.i(Keys.TOKEN_KEY, result.getAccessToken());
        }
    }
};

1。 使用Soap进行本地和在线

2。 使用ADAL的本地和在线 strong>

2. On-Prem and Online using ADAL

这篇关于从Android连接到Dynamics CRM 2016(本地)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆