当前位置: 动力学知识库 > 问答 > 编程问答 >

wsdl - Getting List of on Hold users for office 365 through EWS

问题描述:

I am using the EWS java api to fetch the list of users on hold.I have downloaded the wsdl file from https://outlook.office365.com/EWS/Services.wsdl

and generated the required classes. I am targeting the below service , from the wsdl:

 <wsdl:message name="GetHoldOnMailboxesSoapIn">

<wsdl:part name="request" element="tns:GetHoldOnMailboxes"/>

<wsdl:part name="RequestVersion" element="t:RequestServerVersion"/>

<wsdl:part name="ManagementRole" element="t:ManagementRole"/>

</wsdl:message>

<wsdl:message name="GetHoldOnMailboxesSoapOut">

<wsdl:part name="GetHoldOnMailboxesResult" element="tns:GetHoldOnMailboxesResponse"/>

<wsdl:part name="ServerVersion" element="t:ServerVersionInfo"/>

</wsdl:message>

Below is the code that , I am using to generate the list:

import java.util.Iterator;

import java.util.List;

import microsoft.exchange.webservices.data.autodiscover.IAutodiscoverRedirectionUrl;

import microsoft.exchange.webservices.data.core.ExchangeService;

import microsoft.exchange.webservices.data.credential.ExchangeCredentials;

import microsoft.exchange.webservices.data.credential.WebCredentials;

import microsoft.exchange.webservices.data.enumeration.ExchangeVersion;

import com.microsoft.schemas.exchange.services._2006.messages.GetActivityLogResponseMessageType;

import com.microsoft.schemas.exchange.services._2006.messages.GetDiscoverySearchConfigurationResponseMessageType;

import com.microsoft.schemas.exchange.services._2006.messages.GetDiscoverySearchConfigurationType;

import com.microsoft.schemas.exchange.services._2006.messages.GetHoldOnMailboxesResponseMessageType;

import com.microsoft.schemas.exchange.services._2006.messages.GetHoldOnMailboxesType;

import com.microsoft.schemas.exchange.services._2006.messages.ObjectFactory;

import com.microsoft.schemas.exchange.services._2006.types.ArrayOfMailboxHoldStatusType;

import com.microsoft.schemas.exchange.services._2006.types.MailboxHoldStatusType;

//import ews.RedirectionUrlCallback;

public class InPlace {

@SuppressWarnings("resource")

public static void main(String[] args) {

GetDiscoverySearchConfigurationType gt = new GetDiscoverySearchConfigurationType();

ExchangeService service = null;

service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);

ExchangeCredentials credentials = new WebCredentials(

"XXXXXXx", "password");

service.setCredentials(credentials);

/*

* Some additional code

*/

ObjectFactory objc = new ObjectFactory();

GetHoldOnMailboxesResponseMessageType gmt = objc.createGetHoldOnMailboxesResponseMessageType();

ArrayOfMailboxHoldStatusType arm = gmt.getMailboxHoldResult().getMailboxHoldStatuses();

List ar = arm.getMailboxHoldStatus();

Iterator it = ar.iterator();

while(it.hasNext()){

MailboxHoldStatusType mst = (MailboxHoldStatusType)it.next();

System.out.println(mst.getMailbox());

}

}

}

class RedirectionUrlCallback1 implements IAutodiscoverRedirectionUrl {

public boolean autodiscoverRedirectionUrlValidationCallback(

String redirectionUrl) {

return redirectionUrl.toLowerCase().startsWith("https://");

}

}

I know , I am missing something in the code , where I will have to hook the service object with the api class. Please , suggest what I am missing , or if I am completely on a wrong path.

网友答案:

If your going to use Proxy code you will need to use the ExchangeServiceBinding Class to call that operation eg

        ExchangeServiceBinding esb = new ExchangeServiceBinding();
        esb.RequestServerVersionValue = new RequestServerVersion();
        esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2013_SP1;
        esb.Url = "https://outlook.office365.com/EWS/Exchange.asmx";
        esb.Credentials = new NetworkCredential("username", "password");
        esb.CookieContainer = new CookieContainer();
        GetHoldOnMailboxesType ghold = new GetHoldOnMailboxesType();
        ghold.HoldId = "HoldId2";
        GetHoldOnMailboxesResponseMessageType gholdRespons = esb.GetHoldOnMailboxes(ghold);
        if (gholdRespons.ResponseClass == ResponseClassType.Success)
        {
            Console.WriteLine(gholdRespons.MailboxHoldResult.HoldId);
        }

Cheers Glen

分享给朋友:
您可能感兴趣的文章:
随机阅读: