代码之家  ›  专栏  ›  技术社区  ›  mjn anonym

用Java连接到微软动态CRM上的Web服务?

  •  9
  • mjn anonym  · 技术社区  · 15 年前

    是否有任何在线资源显示了用Java编写的客户端访问微软CRM上的Web服务的基本步骤?

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

    我尝试使用JAXB,但WSDL元素命名中存在冲突,这需要自定义类。如果我找到正确的装订方法,我会把它贴在这里。

    4 回复  |  直到 8 年前
        1
  •  8
  •   vulkanino    9 年前

    Microsoft Dynamics CRM应用程序内部部署版本使用Active Directory身份验证。 虽然我从未尝试从Java引用微软动态CRM Web服务,但我确信它是可行的,因为它们是标准的Web服务,因此可以通过Java从SOAP引用,就像任何其他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  
    } 
    
        2
  •  4
  •   Zdenek Svoboda    13 年前
        3
  •  1
  •   Manuel Freiholz    14 年前

    存根是用ApacheAxis2框架创建的。

        4
  •  0
  •   Richard P.    9 年前

    你可以在这里找到资源。您甚至可以使用Dynamics CRM SDK中提供的示例。正如Manuel Freiholz所说,您必须使用Axis2。

    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

    或者,您可以通过Dynamics提供的OData接口使用RESTful Web服务。( https://msdn.microsoft.com/en-us/library/gg334279.aspx )