当前位置: 首页 > 面试题库 >

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

乐修远
2023-03-14
问题内容

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

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

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


问题答案:

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

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 web 服务只是单纯使用 Tomcat 做 Web 服务器,前后端代码融合在一个工程之中。Tomcat 启动后对外提供一个端口接收和相应 http请求。随着 Nginx 的越来越流行,同时加上其优秀的反响代理和负载均衡功能,我们在线上的 Java web 通常会结合二者,即使用 Nginx + Tomcat 的方式来部署 Java web 服务。最近两年,随着微服务化和

  • 我正在尝试将一个简单的web服务部署到GlassFish。以下是web服务类: 任务是一个简单的界面。界面如下: 当我试图通过Netbeans部署web服务时,我得到以下错误:

  • 我试图使用eclipse、tomcat和CXF部署一个简单的Web服务。 3)看起来一切都很好。将web.xml和beans.xml文件添加到WEB-INF文件夹中: web.xml beans.xml

  • 我正在编写一个简单的RESTful Web服务,使用Java、tomcat7、jersey和IDE eclipse。 当我使用eclipse(服务器)启动web服务时,它运行良好。我测试了GET和POST方法。但当我在WAR文件中导出应用程序并使用tomcat manage UI部署时。它返回404 not found状态。 下面是一个例子: 这里是网络。xml: 有人能解释在eclipse中启动

  • 本文向大家介绍使用phpMyAdmin连接到外部服务器,包括了使用phpMyAdmin连接到外部服务器的使用技巧和注意事项,需要的朋友参考一下 下面的代码行可以添加到底部的/etc/phpmyadmin/config.inc.php文件中- 它将显示“当前服务器:”,并同时下拉“ 127.0.0.1”和$cfg ['Servers'] [$i] ['host']提供的下拉列表。 用户可以在两个服务

  • 我想用maven部署一个小型Web应用程序。我下载并配置了tomcat,并告诉IntelliJ在Run/Debug config中使用它,如下所示。我还将其配置为构建神器“战争爆炸”。 问题是,每次我运行项目时,都会出现一个错误,即: 工件JDBCTest:war:服务器未连接。部署不可用。 这是我的带有错误日志的dropbox,pom。xml、servlet类等。 我真的需要一些建议。