是否有任何在線資源顯示使用Java編寫的客戶端訪問Microsoft CRM內部部署Web服務的基本步驟?使用Java連接到Microsoft Dynamics CRM內部部署的Web服務?
我應該使用哪個Web服務工具包?
我嘗試過使用JAXB,但是WSDL元素命名中存在衝突,需要類定製。如果我找到正確的綁定修復,我會在這裏發佈。
是否有任何在線資源顯示使用Java編寫的客戶端訪問Microsoft CRM內部部署Web服務的基本步驟?使用Java連接到Microsoft Dynamics CRM內部部署的Web服務?
我應該使用哪個Web服務工具包?
我嘗試過使用JAXB,但是WSDL元素命名中存在衝突,需要類定製。如果我找到正確的綁定修復,我會在這裏發佈。
預置版本上的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
}
存根已使用Apache Axis2框架創建。
爪哇 - >香皂 - > MS CRM 2011在線:http://zsvoboda.blogspot.com/2011/03/connecting-to-microsoft-crm-2011-online.html
你可以在這裏找到資源。您甚至可以在Dynamics CRM SDK中使用一個示例。正如Manuel Freiholz所說,你必須使用Axis2。
https://msdn.microsoft.com/en-us/library/jj602979(v=crm.5).aspx
或者,您也可以通過動態提供的OData的接口使用RESTful Web服務(https://msdn.microsoft.com/en-us/library/gg334279.aspx)
你實現小姐Dynamics CRM中,如果是的話,讓你指導我實現一樣。尋找你的迴應。 – 2012-11-29 10:24:43
@SenthilMg我們沒有使用過WCF客戶端和簡單的基於文件的消息交換。請參閱下面的提示可以使用Axis 2。 – mjn 2012-11-29 13:56:21