gpt4 book ai didi

java - 使用 Java 连接到 Microsoft Dynamics CRM 本地 Web 服务?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:14:45 24 4
gpt4 key购买 nike

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

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

我尝试使用 JAXB,但 WSDL 元素命名存在冲突,需要类自定义。如果我找到正确的绑定(bind)修复程序,我会在此处发布。

最佳答案

本地版本的 Microsoft Dynamics CRM 应用程序使用 Active Directory 身份验证。尽管我从未尝试过从 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
}

关于java - 使用 Java 连接到 Microsoft Dynamics CRM 本地 Web 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1115865/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com