2016-05-16 86 views
0

我的代碼來發送郵件請求失敗時,我嘗試使用Exchange Web服務

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2); 
ExchangeCredentials credentials = new WebCredentials("[email protected]","pwd"); 
service.setCredentials(credentials); 
service.setUrl(new URI("C:/shiva/Services.asmx")); 
EmailMessage msg = new EmailMessage(service); 
msg.setSubject("Hello world!"); 
msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Java API.")); 
msg.getToRecipients().add("[email protected]"); 
msg.send(); 

我得到當我跑上面的代碼

microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. Protocol C isn't supported for service request. 
    at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:74). 
. 
. 
. 
. 
Caused by: microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException: Protocol C isn't supported for service request. 
    at microsoft.exchange.webservices.data.core.ExchangeServiceBase.prepareHttpWebRequestForUrl(ExchangeServiceBase.java:322). 
. 
. 
. 

請幫助下面的錯誤將郵件發送到Exchange Server我。

+0

是的,@ Bill Shannon。謝謝。 –

回答

1

問題是您不指向您的Exchange Web服務(EWS)實例爲託管的URI。相反,你只是指向位置在文件系統:

service.setUrl(new URI("C:/shiva/Services.asmx")); 

所以URI級試圖解釋C:/因爲這將不會在這種情況下工作的協議。您需要做的事情如下:在Web服務器上託管您的EWS實例(在這種情況下,通常是Microsoft IIS)我想您需要一個Windows服務器來設置所需的服務器角色等)。並讓您的代碼指向該URI:

service.setUrl(new URI("http://localhost:1234/someWhere/Services.asmx")); 
+0

謝謝@khlr。有效。 –

+0

你有本地實例在運行嗎? – khlr

+0

我已經使用了我的組織的服務器。 –

相關問題