2017-01-19 48 views
3

我想Android应用程序与动态CRM 2015年在线和现场集成。
对于网络版Connect Android App to Dynamics CRM using Web API这工作得很好,但不支持OnPremise ADAL依赖。 是否有任何资源显示访问Microsoft CRM本地部件的基本步骤。 任何用于连接到REST端点的示例代码都会很有帮助。连接到动态CRM 2016(内部)从Android的

+0

你为什么认为它不被支持? –

+0

@JamesWood adal图书馆仅支持在线版本 –

回答

0

的预置型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()); 
     } 
    } 
}; 

On-Prem and Online using Soap

2.On-Prem and Online using ADAL

1

设置IFD为您现场部署。

Authenticate to Microsoft Dynamics 365 with the Web API

当您使用Web API的动力学365(在线)或本地 面向Internet的部署(IFD)在 连接描述到Microsoft Dynamics 365,您必须使用OAuth使用OAuth的网络服务。

Connect to Microsoft Dynamics 365 web services using OAuth

适用于:动力365(在线),动力学365(本地), 动态CRM 2016年,Dynamics CRM Online中

推荐认证API对于与动态网页365使用 API是Azure的Active Directory验证库(ADAL),这是 AV适用于各种平台和编程语言。 ADAL API使用Dynamics 365 Web服务身份提供程序管理OAuth 2.0身份验证。有关实际使用的OAuth 协议的更多详细信息,请参阅Use OAuth to Authenticate with the CRM Service

+0

onprem + ifd for android的任何参考 –

0

ADFS需要在炳。请查阅此文档以了解如何设置服务器。 https://msdn.microsoft.com/en-us/library/dn531009(v=crm.7).aspx

如果这是一个客户端,也可能是值得创建应用程序和CRM之间的基于.NET代理一次性的项目。这样,你可以使用.NET软件开发工具包,而无需担心使用失去支持