简体   繁体   English

使用Java连接到Microsoft Dynamics CRM内部部署Web服务?

[英]Connecting to Microsoft Dynamics CRM on-premise web service with Java?

Are there any online resources which show the basic steps to access the Microsoft CRM on-premise web service with a client written in Java? 是否有任何在线资源显示使用Java编写的客户端访问Microsoft CRM内部部署Web服务的基本步骤?

Which web service toolkit should I use? 我应该使用哪个Web服务工具包?

I tried it with JAXB but there is a conflict in the WSDL element naming which requires a class customization. 我尝试使用JAXB,但WSDL元素命名中存在冲突,需要进行类自定义。 If I find the correct binding fix, I will post it here. 如果我找到正确的绑定修复程序,我会在此处发布。

The Microsoft Dynamics CRM application on premise version uses Active Directory authentication. Microsoft Dynamics CRM应用程序本地版本使用Active Directory身份验证。 Although I never tried referencing the Microsoft Dynamics CRM web services from Java, I am sure it is feasible, as these are standard web services and therefor can be referenced from Java via SOAP, just like any other web service. 虽然我从未尝试过使用Java引用Microsoft Dynamics CRM Web服务,但我确信它是可行的,因为它们是标准Web服务,因此可以通过SOAP从Java引用,就像任何其他Web服务一样。

public class TestCRM {  

private static String endpointURL = "http://server:port/MSCrmServices/2007/CrmService.asmx";  
private static String userName = "username";  
private static String password = "password";  
private static String host = "server";  
private static int portport = port;  

//To make sure you are using the correct domain open ie and try to reach the service. The same domain you entered there is needed here  
private static String domain = "DOMAIN";   

private static String orgName = "THIS_IS_REQUIRED"; //this does the work....  


public static void main(String[] args) {  

    CrmServiceStub stub;  
    try {  
        stub = new CrmServiceStub(endpointURL);  
        setOptions(stub._getServiceClient().getOptions());  

        RetrieveMultipleDocument rmd = RetrieveMultipleDocument.Factory.newInstance();  
        RetrieveMultiple rm = RetrieveMultiple.Factory.newInstance();  

        QueryExpression query = QueryExpression.Factory.newInstance();  
        query.setColumnSet(AllColumns.Factory.newInstance());  
        query.setEntityName(EntityName.######.toString());  
        //query.setFilter...  

        rm.setQuery(query);  
        rmd.setRetrieveMultiple(rm);  

        //Now this is required. Without it all i got was 401s errors  
        CrmAuthenticationTokenDocument catd = CrmAuthenticationTokenDocument.Factory.newInstance();  
        CrmAuthenticationToken token = CrmAuthenticationToken.Factory.newInstance();  
        token.setAuthenticationType(0);     
        token.setOrganizationName(orgName);  
        catd.setCrmAuthenticationToken(token);  

        boolean fetchNext = true;  
        while(fetchNext){  
            RetrieveMultipleResponseDocument rmrd = stub.RetrieveMultiple(rmd,  catd, null, null);  
            RetrieveMultipleResponse rmr = rmrd.getRetrieveMultipleResponse();  
            BusinessEntityCollection bec = rmr.getRetrieveMultipleResult();  

            String pagingCookie = bec.getPagingCookie();  
            fetchNext = bec.getMoreRecords();  

            ArrayOfBusinessEntity aobe = bec.getBusinessEntities();  
            BusinessEntity[] myEntitiesAtLast = aobe.getBusinessEntityArray();  

            for(int i=0; i<myEntitiesAtLast.length; i++){  
                //cast to whatever you asked for...  
                ### myEntity = (###) myEntitiesAtLast[i];  
            }  
        }  
    }   
    catch (Exception e) {  
        e.printStackTrace();  
    }  
}  

private static void setOptions(Options options){  
    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();  

    List authSchemes = new ArrayList();  
    authSchemes.add(HttpTransportProperties.Authenticator.NTLM);   
    auth.setAuthSchemes(authSchemes);   

    auth.setUsername(userName);  
    auth.setPassword(password);  
    auth.setHost(host);  
    auth.setPort(port);  
    auth.setDomain(domain);  
    auth.setPreemptiveAuthentication(false); //it doesnt matter...  
    options.setProperty(HTTPConstants.AUTHENTICATE, auth);  
    options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, "true"); //i think this is good.. not required though  
} 

存根是使用Apache Axis2框架创建的。

You can find resources here. 你可以在这里找到资源。 You can even work with an example is available in Dynamics CRM SDK. 您甚至可以使用Dynamics CRM SDK中的示例。 As Manuel Freiholz said, you have to use Axis2. 正如Manuel Freiholz所说,你必须使用Axis2。

https://msdn.microsoft.com/en-us/library/jj602979(v=crm.5).aspx https://msdn.microsoft.com/en-us/library/jj602979(v=crm.5).aspx

http://blogs.msdn.com/b/dynamics-coe/archive/2013/09/21/integrating-microsoft-dynamics-crm-2011-online-with-java-and-other-non-net-clients.aspx http://blogs.msdn.com/b/dynamics-coe/archive/2013/09/21/integrating-microsoft-dynamics-crm-2011-online-with-java-and-other-non-net-clients。 ASPX

Alternatively, you can use RESTFul web services through the OData interface offered by Dynamics ( https://msdn.microsoft.com/en-us/library/gg334279.aspx ) 或者,您可以通过Dynamics提供的OData接口使用RESTFul Web服务( https://msdn.microsoft.com/en-us/library/gg334279.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用CXF调用Microsoft CRM 2011内部部署Web服务 - Calling Microsoft CRM 2011 On-premise web service with CXF 将 java 连接到 Microsoft Dynamics crm - connecting java to microsoft dynamics crm 尝试通过java中的web api连接Microsoft dynamics crm - trying to connect Microsoft dynamics crm by web api in java 将 Java SCP 应用程序连接到内部部署 JCo3 的 ABAP - Connecting Java SCP app to ABAP on-premise JCo3 从 Java 到 Online Federated Dynamics CRM 2013 的 Web 服务身份验证 - Web Service Authentication to Online Federated Dynamics CRM 2013 from Java 从JAVA在线调用Microsoft Dynamics CRM 2011 - Calling Microsoft Dynamics CRM 2011 online from JAVA 如何为MS Dynamics CRM 2011服务生成Java代码 - How to generate Java code for MS Dynamics CRM 2011 Service CRM Dynamics和Java集成错误 - CRM Dynamics and Java Integration error 通过 Selenium 和 Java 使用 IEDriverServer 和 Internet Explorer 在 Microsoft Dynamics CRM 中出现 XPathEvaluator 未定义脚本错误 - XPathEvaluator is undefined’ script error in Microsoft Dynamics CRM using IEDriverServer and Internet Explorer through Selenium and Java How to Create Case in Microsoft Dynamics CRM 2016 (Version 8) using webservices or REST API in JAVA or C#? - How to Create Case in Microsoft Dynamics CRM 2016 (Version 8) using webservices or REST API in JAVA or C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM