[E2010] [EWSMA] [C#] [Windows]: Certificate-based authentication - An error occurred when verifying security for the message RRS feed

  • Question

  • Hello,

    I'm getting an error in my response from the server when I try to use certificate-based credentials. The error is:" Service Response Error: An error occurred when verifying security for the message." I don't have any problems connecting to a mailbox using a username and password.

    // local vars
    string email = "myemail@domain.local";
    string pass = "mypassword";
    string subjectKeyIdentifer = "xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx";
    string endpoint = "https://myserver.domain.local/EWS/Exchange.asmx";
    int throttle = 50;
    //create service object
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
    //get the certificate by subjectKeyIdentifier
    //and create the credentials
    X509Certificate2 x509Cert = getClientCertifcate(subjectKeyIdenifier);
    service.Credentials = new X509CertificateCredentials(x509Cert);
    //if I use username/password credentials like below:
    //I don't have any problems connecting to the service
    //service.credentials = new WebCredentials(email,pass);
    service.Url = new Uri(endpoint);
    //create search criteria
    SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFRilter.IsEqualTo(EmailMessageSchema.IsRead, false));
    PropertySet itemProperySet = new PropertySet(BasePropertySet.FirstClassProperties);
    itemPropertySet.RequestedBodyType = BodyType.Text;
    ItemView itemView = new ItemView(throttle);
    itemVirew.PropertySet = itemProperySet;
      //Code dies here and gives the error
      // doesn't matter if I do a search or create a new email, ect...
       FindItemsResults<Item> findResults = service.FidItems(WellKnownFolderName.Inbox, sf, itemview);
    catch (ServiceResponseException e)
      console.WriteLine(DateTime.Now + ": Service Response Error - " + e);
    Am I missing some piece of code to use a certificate instead of a username/password?  Is there a difference between my request to the server and what the server expects? Any help would be great, thanks.
    Wednesday, June 8, 2016 4:18 PM