none
How to creat SOAP message for Exchange 2013? RRS feed

  • Question

  • Hi,

    I would like to know how to creat SOAP message for Exchange Web Service.

    For examle I need set category "Red" and "Orange" for selected mail.
    Or I want get selected mail as EML or MSG file.
    What is method for creat these request to invoke them from javascript?

    Thanks

    Monday, March 17, 2014 1:37 PM

Answers

  • SOAP messages are just XML documents so you can use any of the normal methods of building XML documents in Javascript or other XML libariies.

    Personally i just use strings and parse the requests using the DomParser https://developer.mozilla.org/en-US/docs/Web/API/DOMParser eg

    function getSoapEnvelope(request) {
        // Wrap an Exchange Web Services request in a SOAP envelope.
        var result =
    
        '<?xml version="1.0" encoding="utf-8"?>' +
        '<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:Header>' +
        '    <RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
        '  </soap:Header>' +
        '  <soap:Body>' +
    
        request +
    
        '  </soap:Body>' +
        '</soap:Envelope>';
    
        return result;
    }
    
    function getItemRequest(id) {
        // Return a GetItem operation request for the subject of the specified item. 
        var result =
     '    <GetItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">' +
     '      <ItemShape>' +
     '        <t:BaseShape>IdOnly</t:BaseShape>' +
     '        <t:AdditionalProperties>' +
     '            <t:FieldURI FieldURI="item:Subject"/>' +
     '            <t:FieldURI FieldURI="item:Body"/>' +
     '        </t:AdditionalProperties>' +
     '      </ItemShape>' +
     '      <ItemIds><t:ItemId Id="' + id + '"/></ItemIds>' +
     '    </GetItem>';
    
        return result;
    }

    Working out the correct formating for SOAP requests can be time cosuming but here are a few things that can help

    Look at the EWSeditor http://ewseditor.codeplex.com/ in the download for this there is a directory called EwsPostExamples which has samples of all the EWSRequests. The application will also show you all the request it uses.

    I would also suggest you use the Managed API and enable tracing http://msdn.microsoft.com/en-us/library/office/dn495632(v=exchg.150).aspx to first build your request the convert it to javascript . You'll find samples for most everything you need to do with EWS for the Managed API for .net and using Tracing you can get the SOAP requests used which you can then just cut and paste into your Javascript code. This will save you many hours of trial and error. eg for sending a Message and setting categories like you have asked you can use

                EmailMessage email = new EmailMessage(service);
                email.Subject = "test";
                email.ToRecipients.Add("user@domain.com");
                email.Body = new MessageBody("test");
                email.Categories.Add("Orange");
                email.Categories.Add("Green");
                service.TraceEnabled = true;
                email.SendAndSaveCopy();

    Which would generate SOAP like

      <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="
    http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://sc
    hemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xml
    soap.org/soap/envelope/">
        <soap:Header>
          <t:RequestServerVersion Version="Exchange2013" />
        </soap:Header>
        <soap:Body>
          <m:CreateItem MessageDisposition="SendAndSaveCopy">
            <m:SavedItemFolderId>
              <t:DistinguishedFolderId Id="sentitems" />
            </m:SavedItemFolderId>
            <m:Items>
              <t:Message>
                <t:Subject>test</t:Subject>
                <t:Body BodyType="HTML">test</t:Body>
                <t:Categories>
                  <t:String>Orange</t:String>
                  <t:String>Green</t:String>
                </t:Categories>
                <t:ToRecipients>
                  <t:Mailbox>
                    <t:EmailAddress>user@domain.com</t:EmailAddress>
                  </t:Mailbox>
                </t:ToRecipients>
              </t:Message>
            </m:Items>
          </m:CreateItem>
        </soap:Body>
      </soap:Envelope>
    Cheers
    Glen 

    • Marked as answer by Prog-NET Wednesday, March 19, 2014 3:29 PM
    Tuesday, March 18, 2014 4:53 AM

All replies

  • Hi Prog-Net,

    Can you try to post the message in the

    http://social.msdn.microsoft.com/Forums/exchange/en-US/home?forum=exchangesvrdevelopment

    On searching for your requirement found the below url

    http://social.msdn.microsoft.com/Forums/exchange/en-US/8731e15c-572a-4584-a5c2-9688ee2e7136/creating-soap-message-cant-insert-html-text-in-the-body-of-the-message?forum=exchangesvrdevelopment

    check it out if it helpful ...


    Exchange Queries

    Tuesday, March 18, 2014 1:20 AM
  • SOAP messages are just XML documents so you can use any of the normal methods of building XML documents in Javascript or other XML libariies.

    Personally i just use strings and parse the requests using the DomParser https://developer.mozilla.org/en-US/docs/Web/API/DOMParser eg

    function getSoapEnvelope(request) {
        // Wrap an Exchange Web Services request in a SOAP envelope.
        var result =
    
        '<?xml version="1.0" encoding="utf-8"?>' +
        '<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:Header>' +
        '    <RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
        '  </soap:Header>' +
        '  <soap:Body>' +
    
        request +
    
        '  </soap:Body>' +
        '</soap:Envelope>';
    
        return result;
    }
    
    function getItemRequest(id) {
        // Return a GetItem operation request for the subject of the specified item. 
        var result =
     '    <GetItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">' +
     '      <ItemShape>' +
     '        <t:BaseShape>IdOnly</t:BaseShape>' +
     '        <t:AdditionalProperties>' +
     '            <t:FieldURI FieldURI="item:Subject"/>' +
     '            <t:FieldURI FieldURI="item:Body"/>' +
     '        </t:AdditionalProperties>' +
     '      </ItemShape>' +
     '      <ItemIds><t:ItemId Id="' + id + '"/></ItemIds>' +
     '    </GetItem>';
    
        return result;
    }

    Working out the correct formating for SOAP requests can be time cosuming but here are a few things that can help

    Look at the EWSeditor http://ewseditor.codeplex.com/ in the download for this there is a directory called EwsPostExamples which has samples of all the EWSRequests. The application will also show you all the request it uses.

    I would also suggest you use the Managed API and enable tracing http://msdn.microsoft.com/en-us/library/office/dn495632(v=exchg.150).aspx to first build your request the convert it to javascript . You'll find samples for most everything you need to do with EWS for the Managed API for .net and using Tracing you can get the SOAP requests used which you can then just cut and paste into your Javascript code. This will save you many hours of trial and error. eg for sending a Message and setting categories like you have asked you can use

                EmailMessage email = new EmailMessage(service);
                email.Subject = "test";
                email.ToRecipients.Add("user@domain.com");
                email.Body = new MessageBody("test");
                email.Categories.Add("Orange");
                email.Categories.Add("Green");
                service.TraceEnabled = true;
                email.SendAndSaveCopy();

    Which would generate SOAP like

      <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="
    http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://sc
    hemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xml
    soap.org/soap/envelope/">
        <soap:Header>
          <t:RequestServerVersion Version="Exchange2013" />
        </soap:Header>
        <soap:Body>
          <m:CreateItem MessageDisposition="SendAndSaveCopy">
            <m:SavedItemFolderId>
              <t:DistinguishedFolderId Id="sentitems" />
            </m:SavedItemFolderId>
            <m:Items>
              <t:Message>
                <t:Subject>test</t:Subject>
                <t:Body BodyType="HTML">test</t:Body>
                <t:Categories>
                  <t:String>Orange</t:String>
                  <t:String>Green</t:String>
                </t:Categories>
                <t:ToRecipients>
                  <t:Mailbox>
                    <t:EmailAddress>user@domain.com</t:EmailAddress>
                  </t:Mailbox>
                </t:ToRecipients>
              </t:Message>
            </m:Items>
          </m:CreateItem>
        </soap:Body>
      </soap:Envelope>
    Cheers
    Glen 

    • Marked as answer by Prog-NET Wednesday, March 19, 2014 3:29 PM
    Tuesday, March 18, 2014 4:53 AM
  • Thanks guys for your answers.
    Glen your answer was that I searched, a big thanks for you.
    Now I can creat SOAP requests for EWS:-).

    With your advice, creating SOAP request that set category to selected email was simply.


      <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="Exchange2013" />
        </soap:Header>
        <soap:Body>
          <m:UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AutoResolve">
            <m:ItemChanges>
              <t:ItemChange>
                <t:ItemId Id="ID OF YOUR EMAIL" />
                <t:Updates>
                  <t:SetItemField>
                    <t:FieldURI FieldURI="item:Categories" />
                    <t:Message>
                      <t:Categories>
                        <t:String>YOUR CATEGORY</t:String>                 
                      </t:Categories>
                    </t:Message>
                  </t:SetItemField>
                </t:Updates>
              </t:ItemChange>
            </m:ItemChanges>
          </m:UpdateItem>
        </soap:Body>
      </soap:Envelope>

    Wednesday, March 19, 2014 3:39 PM