java网页内部发布_使用Java连接到Microsoft Dynamics CRM内部部署Web服务?

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

//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

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值