none
The element 'Contact' in namespace has invalid child element 'CompanyName' RRS feed

  • Question

  • I use EWS API to create contacts in Exchange email account. It worked fine on office 365 server. But failed on some other Exchange servers.  Is there a way to fix this? Thanks!

    Error from the server:

    The request failed schema validation: The element 'Contact' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types' has invalid child element 'CompanyName' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'. List of possible elements expected: 'WeddingAnniversary, HasPicture, PhoneticFullName, PhoneticFirstName, PhoneticLastName, Alias, Notes, Photo, UserSMIMECertificate, MSExchangeCertificate, DirectoryId, ManagerMailbox, DirectReports' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'.

    Here is the xml posted, the values are marked.

    <?xml version="1.0" encoding="UTF-8"?>
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
    <s:Header>
    <t:RequestServerVersion Version="Exchange2010_SP2"/>
    </s:Header>
    <s:Body>
    <m:CreateItem MessageDisposition="SaveOnly">
       <m:SavedItemFolderId>
          <t:DistinguishedFolderId Id="contacts"/>
       </m:SavedItemFolderId>
       <m:Items>
          <t:Contact>
             <t:GivenName>XXXX</t:GivenName>
             <t:Surname>XXXX</t:Surname>
             <t:CompanyName>XXXX</t:CompanyName>
             <t:EmailAddresses>
                <t:Entry Key="EmailAddress1">XXXX</t:Entry>
             </t:EmailAddresses>
             <t:PhoneNumbers>
                <t:Entry Key="BusinessPhone">XXXX</t:Entry>
             </t:PhoneNumbers>
          </t:Contact>
       </m:Items>
    </m:CreateItem>
    </s:Body>

    Thursday, October 9, 2014 2:34 PM

Answers

  • The order of the elements in your XML is wrong this is critical in EWS (or at least it was in 2010) eg in your XML you have Surname before CompanyName where it should be after the PhoneNumber. You can see the proper order in http://msdn.microsoft.com/en-us/library/office/aa581315(v=exchg.150).aspx   .So you need something like

    <soap:Envelope
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
     xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
      <soap:Body>
        <CreateItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" >
          <SavedItemFolderId>
            <t:DistinguishedFolderId Id="contacts"/>
          </SavedItemFolderId>
          <Items>
            <t:Contact>
              <t:FileAs>SampleContact</t:FileAs>
              <t:GivenName>Tanja</t:GivenName>
              <t:CompanyName>Blue Yonder Airlines</t:CompanyName>
              <t:EmailAddresses>
                <t:Entry Key="EmailAddress1">tplate@example.com</t:Entry>
              </t:EmailAddresses>
              <t:PhysicalAddresses>
                <t:Entry Key="Business">
                  <t:Street>1234 56th Ave</t:Street>
                  <t:City>La Habra</t:City>
                  <t:State>CA</t:State>
                  <t: CountryOrRegion>USA</t: CountryOrRegion>
                </t:Entry>
              </t:PhysicalAddresses>
              <t:PhoneNumbers>
                <t:Entry Key="BusinessPhone">4255550199</t:Entry>
              </t:PhoneNumbers>
              <t:JobTitle>Manager</t:JobTitle>
              <t:Surname>Plate</t:Surname>
            </t:Contact>
          </Items>
        </CreateItem>
      </soap:Body>
    </soap:Envelope>
    Cheers
    Glen


    • Edited by Glen ScalesMVP Friday, October 10, 2014 2:20 AM
    • Marked as answer by TingXu Friday, October 10, 2014 3:12 AM
    Friday, October 10, 2014 2:20 AM

All replies

  • I think there is some problem with the soap request . 

    Please follow the below blog and check the soap request and ews impersonation are correct

    http://msdn.microsoft.com/en-us/library/bb204088(EXCHG.80).aspx

     

    Remember to mark as helpful if you find my contribution useful or as an answer if it does answer your question.That will encourage me - and others - to take time out to help you Check out my latest blog posts on http://exchangequery.com Thanks Sathish (MVP)

    Thursday, October 9, 2014 3:55 PM
  • The order of the elements in your XML is wrong this is critical in EWS (or at least it was in 2010) eg in your XML you have Surname before CompanyName where it should be after the PhoneNumber. You can see the proper order in http://msdn.microsoft.com/en-us/library/office/aa581315(v=exchg.150).aspx   .So you need something like

    <soap:Envelope
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
     xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
      <soap:Body>
        <CreateItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" >
          <SavedItemFolderId>
            <t:DistinguishedFolderId Id="contacts"/>
          </SavedItemFolderId>
          <Items>
            <t:Contact>
              <t:FileAs>SampleContact</t:FileAs>
              <t:GivenName>Tanja</t:GivenName>
              <t:CompanyName>Blue Yonder Airlines</t:CompanyName>
              <t:EmailAddresses>
                <t:Entry Key="EmailAddress1">tplate@example.com</t:Entry>
              </t:EmailAddresses>
              <t:PhysicalAddresses>
                <t:Entry Key="Business">
                  <t:Street>1234 56th Ave</t:Street>
                  <t:City>La Habra</t:City>
                  <t:State>CA</t:State>
                  <t: CountryOrRegion>USA</t: CountryOrRegion>
                </t:Entry>
              </t:PhysicalAddresses>
              <t:PhoneNumbers>
                <t:Entry Key="BusinessPhone">4255550199</t:Entry>
              </t:PhoneNumbers>
              <t:JobTitle>Manager</t:JobTitle>
              <t:Surname>Plate</t:Surname>
            </t:Contact>
          </Items>
        </CreateItem>
      </soap:Body>
    </soap:Envelope>
    Cheers
    Glen


    • Edited by Glen ScalesMVP Friday, October 10, 2014 2:20 AM
    • Marked as answer by TingXu Friday, October 10, 2014 3:12 AM
    Friday, October 10, 2014 2:20 AM