miércoles, 20 de junio de 2012

CRM & Java

Una buena pregunta surgió en el Foro de Dynamics CRM. Se trata del mundo de Java y CRM 2011. Bueno la pregunta fue de cómo se puede conectar uno a través de Java al CRM y claro, a mi parecer, la conexión es parecida al que se realiza con C# (bueno, en Java hay que poner más set en realidad je je).

Cuento con un código para la conexión de Java y CRM 4, aunque esta misma debería de funcionar con el CRM 2011 ya que los servicios del CRM 4 están todavía “activos” en el actual CRM.

El código es el siguiente

 

   1:  private static String endpointURL = "http://server:port/MSCrmServices/2007/CrmService.asmx";  
   2:  private static String userName = "username";  
   3:  private static String password = "password";  
   4:  private static String host = "server";  
   5:  private static int portport = port;  
   6:   
   7:  private static String domain = "DOMAIN";   
   8:  private static String orgName = "Org"; 
   9:  public static void main(String[] args) {  
  10:      CrmServiceStub stub;  
  11:      try {  
  12:          stub = new CrmServiceStub(endpointURL);  
  13:          setOptions(stub._getServiceClient().getOptions());  
  14:          RetrieveMultipleDocument rmd = RetrieveMultipleDocument.Factory.newInstance();  
  15:          RetrieveMultiple rm = RetrieveMultiple.Factory.newInstance();  
  16:   
  17:          QueryExpression query = QueryExpression.Factory.newInstance();  
  18:          query.setColumnSet(AllColumns.Factory.newInstance());  
  19:          query.setEntityName(EntityName.<Entidad>.toString());  
  20:          //query.setFilter...  
  21:   
  22:          rm.setQuery(query);  
  23:          rmd.setRetrieveMultiple(rm);  
  24:   
  25:         CrmAuthenticationTokenDocument catd = CrmAuthenticationTokenDocument.Factory.newInstance();  
  26:          CrmAuthenticationToken token = CrmAuthenticationToken.Factory.newInstance();  
  27:          token.setAuthenticationType(0);     
  28:          token.setOrganizationName(orgName);  
  29:          catd.setCrmAuthenticationToken(token);  
  30:   
  31:          boolean fetchNext = true;  
  32:          while(fetchNext){  
  33:              RetrieveMultipleResponseDocument rmrd = stub.RetrieveMultiple(rmd,  catd, null, null);  
  34:              RetrieveMultipleResponse rmr = rmrd.getRetrieveMultipleResponse();  
  35:              BusinessEntityCollection bec = rmr.getRetrieveMultipleResult();  
  36:              String pagingCookie = bec.getPagingCookie();  
  37:              fetchNext = bec.getMoreRecords();  
  38:              ArrayOfBusinessEntity aobe = bec.getBusinessEntities();  
  39:              BusinessEntity[] myEntitiesAtLast = aobe.getBusinessEntityArray();  
  40:   
  41:              for(int i=0; i<myEntitiesAtLast.length; i++){  
  42:          //Lo que quieras hacer
  43:              }  
  44:          }  
  45:      }   
  46:      catch (Exception e) {  
  47:          e.printStackTrace();  
  48:      }  
  49:  }  
  50:   
  51:  private static void setOptions(Options options){  
  52:      HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();  
  53:   
  54:      List authSchemes = new ArrayList();  
  55:      authSchemes.add(HttpTransportProperties.Authenticator.NTLM);   
  56:      auth.setAuthSchemes(authSchemes);   
  57:      auth.setUsername(userName);  
  58:      auth.setPassword(password);  
  59:      auth.setHost(host);  
  60:      auth.setPort(port);  
  61:      auth.setDomain(domain);
  62:  auth.setPreemptiveAuthentication(false);
  63:  options.setProperty(HTTPConstants.AUTHENTICATE, auth);
  64:  options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, "true");
  65:  }

Ahora, investigando un poco me he encontrado con algunos post y un código en Java que nos ayudara a la conexión.

Les dejo acá los link que tales les puedan interesar.

Salu2

Atilin

Share this post
  • Share to Facebook
  • Share to Twitter
  • Share to Google+
  • Share to Email
  • More...

0 comentarios

 
© 2011 Dynamics CRM Rulez !!!!!!
Designed by BlogThietKe Cooperated with Duy Pham
Released under Creative Commons 3.0 CC BY-NC 3.0
Posts RSSComments RSS
Back to top