从WCF运行时出现EWS错误

时间:2012-02-19 23:37:58

标签: c# .net wcf exchange-server exchangewebservices

我正在尝试使用EWS访问我的电子邮件。它从Console应用程序正常工作。但是,当我尝试使用WCF服务访问同一段代码时,它给了我错误:

  

将请求作为没有邮箱的帐户发出时,必须为任何可分辨文件夹ID指定邮箱主SMTP地址

这是我的代码:

        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));

非常感谢任何帮助

编辑1:我正在从WP7应用程序调用此WCF服务,这里是ServiceReferences.ClientConfig设置

    <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>

1 个答案:

答案 0 :(得分:2)

在我的服务方法中,我禁用了模拟并修复了它

[OperationBehavior(Impersonation = ImpersonationOption.NotAllowed)]