Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'am developing SharePoint provider-hosted app deployed on Azure Websites. I found, that it could be possible to create and send a meeting appointments via EWS Managed API:

MSDN Artice

I have some problems Authenticating to EWS using OAuth, here's the code:

ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);

service.TraceEnabled = true;
service.UseDefaultCredentials = false;

KeyValuePair<String, Microsoft.Exchange.WebServices.Data.ClientAccessTokenType> kvType = new KeyValuePair<string, Microsoft.Exchange.WebServices.Data.ClientAccessTokenType>("ClientId-from-Office-Marketplace", ClientAccessTokenType.CallerIdentity);

List<KeyValuePair<String, Microsoft.Exchange.WebServices.Data.ClientAccessTokenType>> tknreq = new List<KeyValuePair<string, Microsoft.Exchange.WebServices.Data.ClientAccessTokenType>>();

tknreq.Add(kvType);
ServiceResponseCollection<GetClientAccessTokenResponse> TokenResponse = service.GetClientAccessToken(tknreq);

OAuthCredentials oaCred = new OAuthCredentials(TokenResponse[0].TokenValue);
service.Credentials = oaCred;

The Exception says:

The Url property on the ExchangeService object must be set.

   at Microsoft.Exchange.WebServices.Data.ExchangeService.Validate()
   at Microsoft.Exchange.WebServices.Data.GetClientAccessTokenRequest.Validate()
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request)
   at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
   at Microsoft.Exchange.WebServices.Data.ExchangeService.GetClientAccessToken(IEnumerable`1 idAndTypes)
   at Solution.Models.Helpers.ExchangeHelper.SendInvitations(String author, Event ev)

After adding:

service.AutodiscoverUrl(author, (a) =>
                    {
                        return true;
                    });

before OAuth setting, the Exception says, that it needs Credentials:

Credentials are required to make a service request.

   at Microsoft.Exchange.WebServices.Data.ExchangeServiceBase.PrepareHttpWebRequestForUrl(Uri url, Boolean acceptGzipEncoding, Boolean allowAutoRedirect)
   at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverRequest.InternalExecute()
   at Microsoft.Exchange.WebServices.Autodiscover.GetUserSettingsRequest.Execute()
   at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetUserSettings(List`1 smtpAddresses, List`1 settings, Nullable`1 requestedVersion, Uri& autodiscoverUrl)
   at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetSettings[TGetSettingsResponseCollection,TSettingName](List`1 identities, List`1 settings, Nullable`1 requestedVersion, GetSettingsMethod`2 getSettingsMethod, Func`1 getDomainMethod)
   at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(List`1 smtpAddresses, List`1 settings)
   at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetSoapUserSettings(String smtpAddress, List`1 requestedSettings)
   at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames)
   at Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress, ExchangeVersion requestedServerVersion, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
   at Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
   at Solution.Models.Helpers.ExchangeHelper.SendInvitations(String author, Event ev)

So this is infinite circle.. How to set Credentials without knowing Service URL (which will be Autodiscovered) or how to Autodiscover Service URL without Credentials? I am confused. Have someone worked with EWS Managed API + SharePoint 2013?

Thanks in advance.

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.