使用Java连接到Microsoft Dynamics CRM内部部署Web服务吗? [英] Connecting to Microsoft Dynamics CRM on-premise web service with Java?

查看:79
本文介绍了使用Java连接到Microsoft Dynamics CRM内部部署Web服务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何在线资源显示了使用Java编写的客户端访问Microsoft CRM内部部署Web服务的基本步骤?

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?

哪个Web服务工具包应我使用了吗?

Which web service toolkit should I use?

我用JAXB尝试过,但是WSDL元素命名中存在冲突,需要进行类自定义。如果找到正确的绑定修复程序,则将其发布在此处。

I tried it with JAXB but there is a conflict in the WSDL element naming which requires a class customization. If I find the correct binding fix, I will post it here.

推荐答案

Microsoft Dynamics CRM应用程序前提版本使用Active Directory身份验证。
尽管我从未尝试过从Java引用Microsoft Dynamics CRM Web服务,但我确信它是可行的,因为它们是标准Web服务,因此可以像其他任何Web服务一样通过SOAP从Java中引用。

The Microsoft Dynamics CRM application on premise version uses Active Directory authentication. 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.

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  
} 

这篇关于使用Java连接到Microsoft Dynamics CRM内部部署Web服务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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