
String url = "https://my-server/EWS/exchange.asmx";ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);service.setTraceEnabled(true);service.setCredentials(new WebCredentials("user","password"));service.setUrl(url.toURI());MailBox mailBox = new MailBox("foo@bar.com");FolderID folder = new FolderID(WellKNownFoldername.InBox,mailBox);ItemVIEw vIEw = new ItemVIEw(10);vIEw.getorderBy().add(ItemSchema.DateTimeReceived,SortDirection.Descending);FindItemsResults<Item> items = service.findItems(folder,vIEw); 不幸的是,此代码抛出以下错误:
Exception in thread "main" microsoft.exchange.webservices.data.EWShttpException: Connection not established at microsoft.exchange.webservices.data.httpClIEntWebRequest.throwIfConnIsNull(UnkNown Source) at microsoft.exchange.webservices.data.httpClIEntWebRequest.getResponseCode(UnkNown Source) at microsoft.exchange.webservices.data.EwsUtilitIEs.formathttpResponseheaders(UnkNown Source) at microsoft.exchange.webservices.data.ExchangeServiceBase.tracehttpResponseheaders(UnkNown Source) at microsoft.exchange.webservices.data.ExchangeServiceBase.processhttpResponseheaders(UnkNown Source) at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(UnkNown Source) at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(UnkNown Source) at microsoft.exchange.webservices.data.ExchangeService.findItems(UnkNown Source) at microsoft.exchange.webservices.data.ExchangeService.findItems(UnkNown Source) at foo.bar.TestMail.main(TestMail.java:52)
我无法理解当前代码的错误.你有任何线索,或至少一些测试尝试?
请注意,我的Java代码可以访问Web服务(https // my-server / exchange.asmx).
不确定它是否可以提供帮助,但我发现在日志显示的跟踪中:
<Trace Tag="EwsResponse" TID="1" Time="2013-01-28 10:47:03Z"><HTML><head><Title>Error</Title></head><body>The function requested is not supported</body></HTML></Trace>
编辑
我做了另一个测试.这一次,我使用默认凭据 – 所以我自己的电子邮件帐户 – 使用service.setUseDefaultCredentials(true);而不是设置WebCredentials对象.连接仍然没有建立,但我得到另一个错误(我只采取了跟踪日志的有趣部分):
<h1>You are not authorized to vIEw this page</h1>You do not have permission to vIEw this directory or page using the credentials that you supplIEd because your Web browser is sending a WWW-Authenticate header fIEld that the Web server is not configured to accept.(...)<h2>http Error 401.2 - Unauthorized: Access is denIEd due to server configuration.<br>Internet information Services (IIS)</h2>
当然,我无法在Exchange服务器端访问或更改任何内容.有没有办法使身份验证成功?
解决方法 问题是由于使用的身份验证方案.默认情况下,EWS使用NTLM,但我的Exchange服务器未配置为接受此类身份验证.我必须使用LDAP身份验证. 总结以上是内存溢出为你收集整理的无法建立与Exchange Web服务的连接 – Java API全部内容,希望文章能够帮你解决无法建立与Exchange Web服务的连接 – Java API所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)