我想我已经用尽了这个选项。我已经在互联网上搜索了好几天,找不到有类似问题的人。
我使用EWS Java API 1.2.1连接到Exchange服务器并打开我的收件箱文件夹以查找电子邮件。这是我的代码:
import java.net.URI;
import microsoft.exchange.webservices.data.*;
public class Connection {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials credentials = new WebCredentials("myUser", "myPass");
service.setCredentials(credentials);
service.setUrl(new URI("https://example.com/ews/exchange.asmx"));
service.setTraceEnabled(true);
Folder inbox = Folder.bind(service, WellKnownFolderName.Inbox);
System.out.println("messages: " + inbox.getTotalCount());
}
}
当我运行它时,我收到以下错误:
Exception in thread "main" microsoft.exchange.webservices.data.ServiceLocalException: https://example.com/ews/exchange.asmx : Connection error
at microsoft.exchange.webservices.data.ExchangeServiceBase.prepareHttpWebRequestForUrl(Unknown Source)
at microsoft.exchange.webservices.data.ExchangeService.prepareHttpWebRequest(Unknown Source)
at microsoft.exchange.webservices.data.ServiceRequestBase.buildEwsHttpWebRequest(Unknown Source)
at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(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.bindToFolder(Unknown Source)
at microsoft.exchange.webservices.data.ExchangeService.bindToFolder(Unknown Source)
at microsoft.exchange.webservices.data.Folder.bind(Unknown Source)
at microsoft.exchange.webservices.data.Folder.bind(Unknown Source)
at Connection.main(Connection.java:22)
我认为这可能会阻止我的连接尝试,但是当我使用JWebServices API时,它确实可以使用上述URL和用户凭据。
顺便说一句,我也可以从我的浏览器访问WSDL。
任何线索?
提前致谢!
答案 0 :(得分:4)
这可能是因为引用了此类的错误JAR。
您使用的JAR是什么?这里使用的是哪个版本的EWS API。??
我在使用EWS API 1.2时遇到了同样的问题,在引用以下JAR之后,它得到了解决。
EWSJavaAPI_1.2original.jar, EWSJavaAPIWithJars_1.2.1.jar, HttpClient的-4.2.5.jar, 的HttpCore-4.2.4.jar, JCIFS-1.3.17.jar, 公地编解码器1.7.jar, 共享记录-1.1.1.jar
EWSJavaAPI_1.2original.jar - 这是与微软相关的类 EWSJavaAPIWithJars_1.2.1.jar - 这个有连接相关的类。
尝试添加这些JAR。
的问候,
Ramesh G。