none
Contacts using EWS Managed API & XML RRS feed

  • Question

  • Hello all,

    I am new to EWS.

    There is a webdav application which syncs exchange contacts with a database. This program generates xml to create/edit/delete contacts. I am replacing this with a C# class using EWS Managed API.

    Is there a way to create/edit/delete contacts using xml instead of creating a contact and then setting its properties? Can I replace this code with some xml method?

    Contact myContact = new Contact(service);
    myContact.GivenName = "John";
    myContact.Surname = "Smith";
    myContact.FileAsMapping = FileAsMapping.SurnameCommaGivenName;
    myContact.CompanyName = "S Company";
    myContact.PhoneNumbers[PhoneNumberKey.BusinessPhone] = "123-456-7890";
    myContact.PhoneNumbers[PhoneNumberKey.HomePhone] = "666-555-4444";
    myContact.PhoneNumbers[PhoneNumberKey.MobilePhone] = "777-888-9999";
    myContact.Save(myFolder.Id);

    Your help is very much appreciated.

    Thanks.


    • Edited by Vishnugupt Wednesday, March 30, 2016 4:07 PM updated
    Wednesday, March 30, 2016 4:04 PM

Answers

  • >> Please bear with me as I am a complete novice

    Okay than I would strongly advise that you use the EWS Managed API this will cut you development time very significantly and be much better code why use Msxml2.XMLHTTP ?

    >>The super user I am using has impersonation rights to all mailboxes. I have verified it using EWS API.

    Okay but you will need to then add the impersonation header into each request see https://msdn.microsoft.com/en-us/library/office/dn722378(v=exchg.150).aspx

    >>Also, can you post a sample to send an email and also to create a contact?

    I don't have any such samples for the method your trying to use as I haven't used that object for quite a long time my suggestion is you post the code your having a problem with (although again I recommend you look at the EWS Managed API) and somebody maybe able to help. If you download the EWS Editor https://ewseditor.codeplex.com/ in the EwsPostExamples folder there are sample XML requests for most operations or you can easily just use the EWS Managed API traces and transpose them. You will still need to write all the parsing code to parse the results.

    Cheers
    Glen

    • Marked as answer by Vishnugupt Thursday, April 21, 2016 7:39 PM
    Monday, April 4, 2016 2:38 AM

All replies

  • >> There is a webdav application which syncs exchange contacts with a database. This program generates xml to create/edit/delete contacts

    EWS is just a SOAP (Simple object access Protocol which use XML) Web Service so you can use what ever Http classes you want (as long as it supports the underlying auth mechanism your using either NTLM,Basic or Oauth).You can just take the XML the above code generates for you and use it (look at using Trace listener to capture the full request https://msdn.microsoft.com/en-us/library/office/dd633676(v=exchg.80).aspx

    However using the Managed API is going to substantially reduce your development time as it creating/parsing the underlying SOAP XML for, eg try debugging what you have written above to the XML equivalent adding on top the Submit and Parsing code you will need.

    Cheers
    Glen   



    Thursday, March 31, 2016 2:50 AM
  • Thanks Glen.

    I am getting a 400 bad request. Could you tell me what is wrong with this?

    Here is my request:

    <?xml version="1.0" encoding="utf-8"?> 
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"  
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"  
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
     <soap:Header> 
       <t:RequestServerVersion Version="Exchange2010" /> 
      </soap:Header> 
      <soap:Body> 
    	 <m:CreateFolder> 
    		<m:ParentFolderId> 
    		  <t:DistinguishedFolderId Id="contacts" /> 
    		</m:ParentFolderId> 
    		<m:Folders> 
    		  <t:Folder> 
    			 <t:FolderClass>IPF.Contact</t:FolderClass> 
    			 <t:DisplayName>SU Contacts (Read Only)</t:DisplayName> 
    			 <t:PermissionSet> 
    				<t:Permissions /> 
    			 </t:PermissionSet> 
    		  </t:Folder> 
    		</m:Folders> 
    	 </m:CreateFolder> 
      </soap:Body> 
    </soap:Envelope>

    I have another problem. Right now the url for the contact includes the database primary key using which we can identify contacts. Can I have a similar approach with EWS? Which property can I use to store the database primary key?

    Thanks again.

    Thursday, March 31, 2016 8:15 PM
  • That request works okay for me I would say its probably to do with the class your using to send it so you should need to show that cde you might want to use fiddler to try and capture the actual request as its being submitted. I would also get rid of the <t:PermissionSet> but having it blank like it should be okay. (Also you are sending this to the EWS endpoint ?)

    >> Right now the url for the contact includes the database primary key using which we can identify contacts. Can I have a similar approach with EWS? Which property can I use to store the database primary key?

    I would suggest you read https://msdn.microsoft.com/en-us/library/office/dn605828(v=exchg.150).aspx , it more reliable to use your own sync property then rely on identifiers that change (the dav:href had simular issue so the shortcut is just use the ewsId which will have simular issue to what you have now).

    Cheers
    Glen


    Friday, April 1, 2016 1:50 AM
  • Please bear with me as I am a complete novice.  I am using Msxml2.XMLHTTP - the same object used for webDAV.

    This is how my Open statement looks like:

    objHTTP.Open ("MKCOL", "http://<servername>/Exchange/<firstname.lastname>/SUContacts (Read Only)", "super.user", "pwd")

    The super user I am using has impersonation rights to all mailboxes. I have verified it using EWS API.

    Also, can you post a sample to send an email and also to create a contact?

    Thanks a lot!



    • Edited by Vishnugupt Friday, April 1, 2016 3:13 PM
    • Marked as answer by Vishnugupt Monday, April 11, 2016 8:54 PM
    • Unmarked as answer by Vishnugupt Thursday, April 21, 2016 7:39 PM
    Friday, April 1, 2016 3:10 PM
  • >> Please bear with me as I am a complete novice

    Okay than I would strongly advise that you use the EWS Managed API this will cut you development time very significantly and be much better code why use Msxml2.XMLHTTP ?

    >>The super user I am using has impersonation rights to all mailboxes. I have verified it using EWS API.

    Okay but you will need to then add the impersonation header into each request see https://msdn.microsoft.com/en-us/library/office/dn722378(v=exchg.150).aspx

    >>Also, can you post a sample to send an email and also to create a contact?

    I don't have any such samples for the method your trying to use as I haven't used that object for quite a long time my suggestion is you post the code your having a problem with (although again I recommend you look at the EWS Managed API) and somebody maybe able to help. If you download the EWS Editor https://ewseditor.codeplex.com/ in the EwsPostExamples folder there are sample XML requests for most operations or you can easily just use the EWS Managed API traces and transpose them. You will still need to write all the parsing code to parse the results.

    Cheers
    Glen

    • Marked as answer by Vishnugupt Thursday, April 21, 2016 7:39 PM
    Monday, April 4, 2016 2:38 AM