2017-01-19 47 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軟件開發工具包,而無需擔心使用失去支持