I’m trying to access my email using EWS. It is working fine from a Console application. But when I’m trying to access same piece of code using WCF service it is giving me error:
When making a request as an account that does not have a mailbox, you must specify the mailbox primary SMTP address for any distinguished folder Ids
Here is my code :
ExchangeService service = new ExchangeService();
service.Credentials = new WebCredentials("username", "password");
service.TraceEnabled = true;
service.AutodiscoverUrl("emailID");
FindItemsResults<Item> findResults = service.FindItems(
WellKnownFolderName.Inbox,
new ItemView(10));
Any help will be greatly appreciated
Edit 1: I’m calling this WCF service from a WP7 app and here is the ServiceReferences.ClientConfig setting
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ITestService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://MachineIP/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ITestService" contract="ServiceReference1.ITestService"
name="BasicHttpBinding_ITestService" />
</client>
</system.serviceModel>
In my service method I disable Impersonation and it got fixed
[OperationBehavior(Impersonation = ImpersonationOption.NotAllowed)]