Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add attributes to an XML node. #75

Closed
IuliuMoga opened this issue Sep 28, 2015 · 24 comments
Closed

How to add attributes to an XML node. #75

IuliuMoga opened this issue Sep 28, 2015 · 24 comments

Comments

@IuliuMoga
Copy link

Hey, I want to start by saying "good library".
The authentication part works well, my actual problem is that I don't manage to build an XML for exchange web services, and I would love to buy license to use this library in my project.
Basicaly i try to achieve is this xml:

  <soap:Body>
    <CreateFolder xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\">
      <ParentFolderId>
        <t:DistinguishedFolderId Id=\"msgfolderroot\"/>
      </ParentFolderId>
      <Folders>
        <t:Folder>
          <t:DisplayName>Folder1</t:DisplayName>
        </t:Folder>
        <t:Folder>
          <t:DisplayName>Folder2</t:DisplayName>
        </t:Folder>
      </Folders>
    </CreateFolder>
  </soap:Body>

My question is how to combine soap setValue functions to achieve an xml node like this:

<ParentFolderId>
        <t:DistinguishedFolderId Id="msgfolderroot"/>
</ParentFolderId>

I keep trying to use all combinations but still Im not being able to build that xml for the envelope body and due this problem the server answers me back with a schema validation fail.

@priore
Copy link
Owner

priore commented Sep 28, 2015

Hi,
this version does not support the attributes to child, only on the parent, but we can implement this functionality in a short time, we are always open to expand the our library with other features.

@IuliuMoga
Copy link
Author

Thank you for your response;
I would recommend to consider broadly used SOAP APIs as use cases for this library.
My current focus is EWS (Exchange Web Services) that is complex and it might be a good start point to implement your generic SOAP API.

priore added a commit that referenced this issue Sep 29, 2015
@priore
Copy link
Owner

priore commented Sep 29, 2015

with this new version you can create sub-attributes, important: the sub-item is a dictionary with two keys named "value" and "attributes", where attribute is a dictionary. In future versions we will see how to simplify this process.

NSDictionary @attr = @{@"Id": @"msgfolderroot"};
NSDictionary *value = @{@"value": @"", @"attributes": attr};
NSDictionary *child = @{@"t:DistinguishedFolderId": value};
[soap setValue:child forKey:@"ParentFolderId"];

@IuliuMoga
Copy link
Author

@priore Thank you for making this possible! I will test this today ASAP to see if it works properly for my use cases.

Have a nice day!

@IuliuMoga
Copy link
Author

@priore Tested and for the above request its working, but now I don't manage to send a soap action with attributes:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
  <soap:Body>
    <FindFolder Traversal="Shallow" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
      <FolderShape>
        <t:BaseShape>Default</t:BaseShape>
      </FolderShape>
      <ParentFolderIds>
        <t:DistinguishedFolderId Id="inbox"/>
      </ParentFolderIds>
    </FindFolder>
  </soap:Body>
</soap:Envelope>

I cannot build this action.

 <FindFolder Traversal="Shallow" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">

Thanks for your support and patience!

@priore
Copy link
Owner

priore commented Sep 30, 2015

This is another enhancement to be added :)

thanks

@IuliuMoga
Copy link
Author

@priore Ok, no problem, thanks a lot, I just want to manage to use your library in my code and EWS has complex soap stuff.
Basicaly It needs to be introduced attributes for Soap action, if I'm not mistaking...

priore added a commit that referenced this issue Oct 1, 2015
@priore
Copy link
Owner

priore commented Oct 1, 2015

added a method named dictionaryForKey for the easy creation of a sub-key with attributes, and a new property named actionAttributes able to add attributes to the SOAP Action https://github.com/priore/SOAPEngine/tree/v1.24

@IuliuMoga
Copy link
Author

@priore Thanks again! for support!

@IuliuMoga
Copy link
Author

@priore Hi, now i will test the new features that you integrated, I will come back if there is need for more support.

@priore
Copy link
Owner

priore commented Oct 2, 2015

@IuliuMoga, that is what we are here to do ;)

You can find an example on the main page, look for the word "Attributes".

@IuliuMoga
Copy link
Author

@priore
Back, thanks it's working now but when I get the response xml the response dictionary is incomplete, it seems that the attributes are not parsed.
Now i want to apologize for the next xml:

for example:

<t:FolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQsAAAA=" ChangeKey="AQAAABYAAABaKdE/VNYYSK5EMpV3Iyu4AAAIXvKk"/>

The FolderId and Change key are missing.
<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><h:ServerVersionInfo MajorVersion="15" MinorVersion="0" MajorBuildNumber="847" MinorBuildNumber="31" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><m:FindFolderResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><m:ResponseMessages><m:FindFolderResponseMessage ResponseClass="Success"><m:ResponseCode>NoError</m:ResponseCode><m:RootFolder TotalItemsInView="13" IncludesLastItemInRange="true"><t:Folders><t:CalendarFolder><t:FolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQ4AAAA=" ChangeKey="AgAAABYAAABaKdE/VNYYSK5EMpV3Iyu4AAAAAAA3"/><t:ParentFolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQkAAAA=" ChangeKey="AQAAAA=="/><t:FolderClass>IPF.Appointment</t:FolderClass><t:DisplayName>Calendar</t:DisplayName><t:TotalCount>0</t:TotalCount><t:ChildFolderCount>0</t:ChildFolderCount></t:CalendarFolder><t:ContactsFolder><t:FolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQ8AAAA=" ChangeKey="AwAAABYAAABaKdE/VNYYSK5EMpV3Iyu4AAAAAAA4"/><t:ParentFolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQkAAAA=" ChangeKey="AQAAAA=="/><t:FolderClass>IPF.Contact</t:FolderClass><t:DisplayName>Contacts</t:DisplayName><t:TotalCount>0</t:TotalCount><t:ChildFolderCount>4</t:ChildFolderCount></t:ContactsFolder><t:Folder><t:FolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACBQkAAAA=" ChangeKey="AQAAABYAAABaKdE/VNYYSK5EMpV3Iyu4AAAAAASx"/><t:ParentFolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQkAAAA=" ChangeKey="AQAAAA=="/><t:FolderClass>IPF.Configuration</t:FolderClass><t:DisplayName>Conversation Action Settings</t:DisplayName><t:TotalCount>0</t:TotalCount><t:ChildFolderCount>0</t:ChildFolderCount><t:UnreadCount>0</t:UnreadCount></t:Folder><t:Folder><t:FolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQsAAAA=" ChangeKey="AQAAABYAAABaKdE/VNYYSK5EMpV3Iyu4AAAIXvKk"/><t:ParentFolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQkAAAA=" ChangeKey="AQAAAA=="/><t:FolderClass>IPF.Note</t:FolderClass><t:DisplayName>Deleted Items</t:DisplayName><t:TotalCount>0</t:TotalCount><t:ChildFolderCount>0</t:ChildFolderCount><t:UnreadCount>0</t:UnreadCount></t:Folder><t:Folder><t:FolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACARAAAAA=" ChangeKey="AQAAABYAAABaKdE/VNYYSK5EMpV3Iyu4AAADHWXP"/><t:ParentFolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQkAAAA=" ChangeKey="AQAAAA=="/><t:FolderClass>IPF.Note</t:FolderClass><t:DisplayName>Drafts</t:DisplayName><t:TotalCount>0</t:TotalCount><t:ChildFolderCount>0</t:ChildFolderCount><t:UnreadCount>0</t:UnreadCount></t:Folder><t:Folder><t:FolderId Id="AAAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAAAALVs6fOh6dVPtt+GqudW294BAFop0T9U1hhIrkQylXcjK7gAAAheie0AAA==" ChangeKey="AQAAABYAAABaKdE/VNYYSK5EMpV3Iyu4AAAIXtsR"/><t:ParentFolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQkAAAA=" ChangeKey="AQAAAA=="/><t:DisplayName>Folder1</t:DisplayName><t:TotalCount>0</t:TotalCount><t:ChildFolderCount>0</t:ChildFolderCount><t:UnreadCount>0</t:UnreadCount></t:Folder><t:Folder><t:FolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQ0AAAA=" ChangeKey="AQAAABYAAABaKdE/VNYYSK5EMpV3Iyu4AAADHV3B"/><t:ParentFolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQkAAAA=" ChangeKey="AQAAAA=="/><t:FolderClass>IPF.Note</t:FolderClass><t:DisplayName>Inbox</t:DisplayName><t:TotalCount>10</t:TotalCount><t:ChildFolderCount>0</t:ChildFolderCount><t:UnreadCount>1</t:UnreadCount></t:Folder><t:Folder><t:FolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAREAAAA=" ChangeKey="BgAAABYAAABaKdE/VNYYSK5EMpV3Iyu4AAAAAAA6"/><t:ParentFolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQkAAAA=" ChangeKey="AQAAAA=="/><t:FolderClass>IPF.Journal</t:FolderClass><t:DisplayName>Journal</t:DisplayName><t:TotalCount>0</t:TotalCount><t:ChildFolderCount>0</t:ChildFolderCount><t:UnreadCount>0</t:UnreadCount></t:Folder><t:Folder><t:FolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACBQgAAAA=" ChangeKey="AQAAABYAAABaKdE/VNYYSK5EMpV3Iyu4AAAAAASp"/><t:ParentFolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQkAAAA=" ChangeKey="AQAAAA=="/><t:FolderClass>IPF.Note</t:FolderClass><t:DisplayName>Junk Email</t:DisplayName><t:TotalCount>0</t:TotalCount><t:ChildFolderCount>0</t:ChildFolderCount><t:UnreadCount>0</t:UnreadCount></t:Folder><t:Folder><t:FolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACARIAAAA=" ChangeKey="BQAAABYAAABaKdE/VNYYSK5EMpV3Iyu4AAAAAAA7"/><t:ParentFolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQkAAAA=" ChangeKey="AQAAAA=="/><t:FolderClass>IPF.StickyNote</t:FolderClass><t:DisplayName>Notes</t:DisplayName><t:TotalCount>0</t:TotalCount><t:ChildFolderCount>0</t:ChildFolderCount><t:UnreadCount>0</t:UnreadCount></t:Folder><t:Folder><t:FolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQwAAAA=" ChangeKey="AQAAABYAAABaKdE/VNYYSK5EMpV3Iyu4AAACdAb9"/><t:ParentFolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQkAAAA=" ChangeKey="AQAAAA=="/><t:FolderClass>IPF.Note</t:FolderClass><t:DisplayName>Outbox</t:DisplayName><t:TotalCount>0</t:TotalCount><t:ChildFolderCount>0</t:ChildFolderCount><t:UnreadCount>0</t:UnreadCount></t:Folder><t:Folder><t:FolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQoAAAA=" ChangeKey="AQAAABYAAABaKdE/VNYYSK5EMpV3Iyu4AAAAgnVi"/><t:ParentFolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQkAAAA=" ChangeKey="AQAAAA=="/><t:FolderClass>IPF.Note</t:FolderClass><t:DisplayName>Sent Items</t:DisplayName><t:TotalCount>14</t:TotalCount><t:ChildFolderCount>0</t:ChildFolderCount><t:UnreadCount>0</t:UnreadCount></t:Folder><t:TasksFolder><t:FolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACARMAAAA=" ChangeKey="BAAAABYAAABaKdE/VNYYSK5EMpV3Iyu4AAAAAAA8"/><t:ParentFolderId Id="AQAaAEFkbWluaXN0cmF0b3JAbHN0ZXRlc3QuY29tAC4AAAO1bOnzoenVT7bfhqrnVtveAQBaKdE/VNYYSK5EMpV3Iyu4AAACAQkAAAA=" ChangeKey="AQAAAA=="/><t:FolderClass>IPF.Task</t:FolderClass><t:DisplayName>Tasks</t:DisplayName><t:TotalCount>0</t:TotalCount><t:ChildFolderCount>0</t:ChildFolderCount><t:UnreadCount>0</t:UnreadCount></t:TasksFolder></t:Folders></m:RootFolder></m:FindFolderResponseMessage></m:ResponseMessages></m:FindFolderResponse></s:Body></s:Envelope>

Get this response:


{
    FindFolderResponseMessage =     {
        ResponseCode = NoError;
        RootFolder =         {
            Folders =             {
                CalendarFolder =                 {
                    ChildFolderCount = 0;
                    DisplayName = Calendar;
                    FolderClass = "IPF.Appointment";
                    FolderId = "";
                    ParentFolderId = "";
                    TotalCount = 0;
                };
                ContactsFolder =                 {
                    ChildFolderCount = 4;
                    DisplayName = Contacts;
                    FolderClass = "IPF.Contact";
                    FolderId = "";
                    ParentFolderId = "";
                    TotalCount = 0;
                };
                Folder =                 (
                                        {
                        ChildFolderCount = 0;
                        DisplayName = "Conversation Action Settings";
                        FolderClass = "IPF.Configuration";
                        FolderId = "";
                        ParentFolderId = "";
                        TotalCount = 0;
                        UnreadCount = 0;
                    },
                                        {
                        ChildFolderCount = 0;
                        DisplayName = "Deleted Items";
                        FolderClass = "IPF.Note";
                        FolderId = "";
                        ParentFolderId = "";
                        TotalCount = 0;
                        UnreadCount = 0;
                    },
                                        {
                        ChildFolderCount = 0;
                        DisplayName = Drafts;
                        FolderClass = "IPF.Note";
                        FolderId = "";
                        ParentFolderId = "";
                        TotalCount = 0;
                        UnreadCount = 0;
                    },
                                        {
                        ChildFolderCount = 0;
                        DisplayName = Folder1;
                        FolderId = "";
                        ParentFolderId = "";
                        TotalCount = 0;
                        UnreadCount = 0;
                    },
                                        {
                        ChildFolderCount = 0;
                        DisplayName = Inbox;
                        FolderClass = "IPF.Note";
                        FolderId = "";
                        ParentFolderId = "";
                        TotalCount = 10;
                        UnreadCount = 1;
                    },
                                        {
                        ChildFolderCount = 0;
                        DisplayName = Journal;
                        FolderClass = "IPF.Journal";
                        FolderId = "";
                        ParentFolderId = "";
                        TotalCount = 0;
                        UnreadCount = 0;
                    },
                                        {
                        ChildFolderCount = 0;
                        DisplayName = "Junk Email";
                        FolderClass = "IPF.Note";
                        FolderId = "";
                        ParentFolderId = "";
                        TotalCount = 0;
                        UnreadCount = 0;
                    },
                                        {
                        ChildFolderCount = 0;
                        DisplayName = Notes;
                        FolderClass = "IPF.StickyNote";
                        FolderId = "";
                        ParentFolderId = "";
                        TotalCount = 0;
                        UnreadCount = 0;
                    },
                                        {
                        ChildFolderCount = 0;
                        DisplayName = Outbox;
                        FolderClass = "IPF.Note";
                        FolderId = "";
                        ParentFolderId = "";
                        TotalCount = 0;
                        UnreadCount = 0;
                    },
                                        {
                        ChildFolderCount = 0;
                        DisplayName = "Sent Items";
                        FolderClass = "IPF.Note";
                        FolderId = "";
                        ParentFolderId = "";
                        TotalCount = 14;
                        UnreadCount = 0;
                    }
                );
                TasksFolder =                 {
                    ChildFolderCount = 0;
                    DisplayName = Tasks;
                    FolderClass = "IPF.Task";
                    FolderId = "";
                    ParentFolderId = "";
                    TotalCount = 0;
                    UnreadCount = 0;
                };
            };
        };
    };
}

@priore
Copy link
Owner

priore commented Oct 2, 2015

try to set retrievesAttributes to YES.

@IuliuMoga
Copy link
Author

@priore
Thanks it's working. I have 2 questions

  1. trying to set this xml
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
  <soap:Body>
    <FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
               xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
              Traversal="Shallow">
      <ItemShape>
        <t:BaseShape>IdOnly</t:BaseShape>
      </ItemShape>
      <ParentFolderIds>
        <t:DistinguishedFolderId Id="deleteditems"/>
      </ParentFolderIds>
    </FindItem>
  </soap:Body>
</soap:Envelope>

FOR

  <FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
               xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
              Traversal="Shallow">
its ok to specfy   xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" as action attribute ?
  1. If I want to execute multiple requests in parralel it's ok to have multiple instances of soap engine ?

Thanks.

@priore
Copy link
Owner

priore commented Oct 2, 2015

you can use the envelope property, with this property you can specify more attributes in soap:envelope, in this case set to your custom namespace, eg.

soap.envelope = @"xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\"";

@priore
Copy link
Owner

priore commented Oct 2, 2015

for multiple requests, you need to create multiple instances, note: the iOS has a limit of multiple http requests, search on google for this.

@IuliuMoga
Copy link
Author

@priore

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
  <soap:Body>
    <CreateItem MessageDisposition="SendAndSaveCopy" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
      <SavedItemFolderId>
        <t:DistinguishedFolderId Id="drafts" />
      </SavedItemFolderId>
      <Items>
        <t:Message>
          <t:ItemClass>IPM.Note</t:ItemClass>
          <t:Subject>Project Action</t:Subject>
          <t:Body BodyType="Text">Priority - Update specification</t:Body>
          <t:ToRecipients>
            <t:Mailbox>
              <t:EmailAddress>sschmidt@example.com</t:EmailAddress>
            </t:Mailbox>
             <t:Mailbox>
              <t:EmailAddress>sschmidt@example2.com</t:EmailAddress>
            </t:Mailbox>
          </t:ToRecipients>
          <t:IsRead>false</t:IsRead>
        </t:Message>
      </Items>
    </CreateItem>
  </soap:Body>
</soap:Envelope>

I try to insert multiple <t:Mailbox> nodes and with NSArray its not working and with NSDictionary won;t let me to insert same key multiple times.
Thanks!

@priore
Copy link
Owner

priore commented Oct 2, 2015

for this complex cases, we recommend build data models, like below:

@interface MainObject : NSObject

@property (nonatomic, strong) NSDictionary *SavedItemFolderId;
@property (nonatomic, strong) NSArray *Items;

- (void)setDistinguisedFolderId:(NSString*)value
                     attributes:(NSDictionary*)attr;

@end

@implementation MainObject

- (void)setDistinguisedFolderId:(NSString*)value
                     attributes:(NSDictionary*)attr
{
    NSDictionary *distinguished =  @{@"value" : value ?: @"", @"attributes": attr ?: @{}};
    self.SavedItemFolderId = @{@"t:DistinguishedFolderId": distinguished};
}

@end

@interface t_Message : NSObject

@property (nonatomic, strong) NSString *ItemClass;
@property (nonatomic, strong) NSString *Subject;
@property (nonatomic, strong) NSDictionary *Body;
@property (nonatomic, strong) NSMutableArray *ToRecipients;

- (void)setBodyValue:(NSString*)value
          attributes:(NSDictionary*)attr;

- (void)addEmailAddress:(NSString*)email;

@end

@implementation t_Message

- (void)setBodyValue:(NSString*)value
          attributes:(NSDictionary*)attr
{
    self.Body = @{@"value": value ?: @"", @"attributes": attr ?: @{}};
}

- (void)addEmailAddress:(NSString*)email
{
    if (self.ToRecipients == nil)
        self.ToRecipients = [NSMutableArray array];

    NSDictionary *emailaddr = @{@"t:EmailAddress": email ?: @""};
    NSDictionary *mailbox = @{@"t:Mailbox": emailaddr};
    [self.ToRecipients addObject:mailbox];
}

@end

and use it in this way:

    soap.defaultTagName = nil; // important!
    soap.envelope = @"xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\"";
    soap.prefixObjectName = @"t_";
    soap.replacePrefixObjectName = @"t:";

    t_Message *msg = [t_Message new];
    msg.ItemClass = @"IPM.Note";
    msg.Subject = @"Project Action";
    [msg setBodyValue:@"Property - Update"
           attributes:@{@"BodyText": @"Text"}];
    [msg addEmailAddress:@"one@email.com"];
    [msg addEmailAddress:@"two@email.com"];

    MainObject *main = [MainObject new];
    main.Items = @[msg, msg];
    [main setDistinguisedFolderId:nil attributes:@{@"Id": @"drafts"}];

    [soap setValue:main];

if it was necessary to specify the namespace (t:) in other tags we need to make new changes, let us know.

@IuliuMoga
Copy link
Author

@priore Ok, Thanks, and with this i think that everything is clear!
Have a nice weekend!

@IuliuMoga
Copy link
Author

@priore
Back to message if it was necessary to specify the namespace (t:) in other tags we need to make new changes, let us know

it Seems that we need to add for subject t:Subject and for body t:Body, i've prefixed their name with t_Subject and t_Body but they are listed in xml as t_Subject and t_Body, I think that some implementation must be added to support this complex types.

@IuliuMoga
Copy link
Author

@priore

Solved more simple:
"Back to message if it was necessary to specify the namespace (t:) in other tags we need to make new changes, let us know

it Seems that we need to add for subject t:Subject and for body t:Body, i've prefixed their name with t_Subject and t_Body but they are listed in xml as t_Subject and t_Body, I think that some implementation must be added to support this complex types."

I think i've solved it more simple:

- (void)sendMessage:(NSString*)subject
               body:(NSString*)body
                 to:(NSArray*)to
                 cc:(NSArray*)cc
                bcc:(NSArray*)bcc
         completion:(EwsSECompletionBlock)completion {

    SOAPEngine *soap = [self createSoap];
    soap.defaultTagName = nil; // important!

    [soap setValue: [soap dictionaryForKey:@"t:DistinguishedFolderId"
                                                           value:nil
                                                      attributes:@{@"Id":@"sentitems"}]
            forKey:@"SavedItemFolderId"];


    NSMutableDictionary *message = [ @{@"t:Subject":subject,
                                       @"t:Body":@{@"value": body, @"attributes":@{@"BodyType": @"HTML"}},
                                       @"t:IsRead":@"false"}
                                    mutableCopy];

    if (to.count) {

        NSMutableArray *arr = [NSMutableArray arrayWithCapacity:to.count];
        for(NSInteger i=0; i<to.count; i++) {
            [arr addObject:@{@"t:Mailbox":@{@"t:EmailAddress":to[0]}}];
        }

        message[@"t:ToRecipients"] = arr;
     }

    [soap setValue:@{@"t:Message":message} forKey:@"Items"];
    soap.actionAttributes = @{@"MessageDisposition" : @"SendAndSaveCopy"};

    [self executeSoap:soap action:@"CreateItem" completion:nil];
}

@priore
Copy link
Owner

priore commented Oct 2, 2015

yes, we found this problem, it is a bug, we fix it soon.

@IuliuMoga
Copy link
Author

@priore Hi, license purchased, what i need now is the possibility to add nodes for SOAP header from a Dictionary, I need to achieve this XML:

<?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="Exchange2007_SP1" />
    </soap:Header>
    <soap:Body>
      <m:CreateItem MessageDisposition="SendAndSaveCopy">
        <m:Items>
          <t:ReplyAllToItem>
            <t:ReferenceItemId Id="AAMkADdlZDg5EAAA=" ChangeKey="CQAAAY3AAAJzqms" />
            <t:NewBodyContent BodyType="Text">This is the message body of the email reply.</t:NewBodyContent>
          </t:ReplyAllToItem>
        </m:Items>
      </m:CreateItem>
    </soap:Body>
  </soap:Envelope>

Thanks.

@priore
Copy link
Owner

priore commented Oct 5, 2015

you can set the property named authorizationMethod to SOAP_AUTH_CUSTOM and the property named header with your custom header, but this accepts only strings, we can implement a new feature for accept other objects types.

Please, open a new issue for this new question, so that we can mark and manage it as "enhancement", and close current issue if the issue was solved, thanks.

@priore priore closed this as completed Oct 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants