使用 Java 连接到 Microsoft Dynamics CRM 内部部署 Web 服务?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1115865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connecting to Microsoft Dynamics CRM on-premise web service with Java?
提问by mjn
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?
是否有任何在线资源显示了使用 Java 编写的客户端访问 Microsoft CRM 内部部署 Web 服务的基本步骤?
Which web service toolkit should I use?
我应该使用哪个 Web 服务工具包?
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.
我用 JAXB 尝试过,但 WSDL 元素命名存在冲突,需要类自定义。如果我找到了正确的绑定修复,我会在这里发布。
采纳答案by joe
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.
本地版本的 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
}
回答by Manuel Freiholz
The stub has been created with the Apache Axis2 framework.
存根是使用 Apache Axis2 框架创建的。
回答by Zdenek Svoboda
Java -> SOAP -> MS CRM 2011 Online : http://zsvoboda.blogspot.com/2011/03/connecting-to-microsoft-crm-2011-online.html
Java -> SOAP -> MS CRM 2011 在线:http: //zsvoboda.blogspot.com/2011/03/connecting-to-microsoft-crm-2011-online.html
回答by Richard P.
You can find resources here. You can even work with an example is available in Dynamics CRM SDK. As Manuel Freiholz said, you have to use Axis2.
你可以在这里找到资源。您甚至可以使用 Dynamics CRM SDK 中提供的示例。正如 Manuel Freiholz 所说,您必须使用 Axis2。
https://msdn.microsoft.com/en-us/library/jj602979(v=crm.5).aspx
https://msdn.microsoft.com/en-us/library/jj602979(v=crm.5).aspx
Alternatively, you can use RESTFul web services through the OData interface offered by Dynamics (https://msdn.microsoft.com/en-us/library/gg334279.aspx)
或者,您可以通过 Dynamics 提供的 OData 接口使用 RESTFul Web 服务 ( https://msdn.microsoft.com/en-us/library/gg334279.aspx)