priore / SOAPEngine

This generic SOAP client allows you to access web services using a your iOS app, Mac OS X app and AppleTV app.
http://www.prioregroup.com
Other
483 stars 75 forks source link

Improve documentation on custom attributes #151

Open felipeferri opened 7 years ago

felipeferri commented 7 years ago

Hi!

First of all, congratulations on this extremely useful library.

I would like to ask you to improve your documentation regarding custom attributes.

I spent some hours trying to do something that I didn't know if was really possible to do with SoapEngine and with some liberal interpretation of some messages exchanges I ended up finding out how to do it, but it would be SOOOO much easier if you documented it up front.. :-)

I was using SoapEngine to connect to a Magento server. At some point, throught some very painful debugging, I found out one of the methods needed to have an array where one of the elements had special attributes, like below:

<args xsi:type="SOAP-ENC:Array">
    <string>2173</string>
    <item xsi:type="ns2:Map">
        <item>
            <key>method</key>
            <value>cartao</value>
        </item>
        <item>
            <key>po_number</key>
            <value>1</value>
        </item>
    </item>
    <double>4</double>
</args>

It is easy to set the "args" tag with the xsi:type="SOAP-ENC:Array" attributes by using [SoapEngine:setValue:forKey:attributes], but I was finding it really hard to set the xsi:type="ns2:Map" attribute to the item tag inside args because it is an element on a list.

I eventually found out that I can create a dictionary which represents a tag using the "value" and "attributes" keys and it would work perfectly.

NSDictionary *paymentMethod = @{@"value":@[@{@"key": @"method",
                                 @"value": @"cartao"},
                               @{@"key": @"po_number",
                                 @"value": @"1"},
                               @{@"key": @"cc_exp_month",
                                 @"value": cardInfo.expirationMonth}],
                               @"attributes": @{@"xsi:type": @"ns2:Map"}};

I didn't find anywhere in the documentation that this is possible; I saw one discussion where you suggest creating a custom class and kinda deduced the above solution from your answers. Please add a similar example to this on your "custom attributes" section on your readme.md because it can help others with the same problem as me.

Thank you and congratulations on your great work!

priore commented 7 years ago

thanks, we will update the documentation as soon as possible.

rajkhatri commented 5 years ago

Just letting you know this helped me, and it probably took me 5+ hours to figure this out. I tried so many things, and this was the final step for me. Also an example would be awesome instead of using key value above, since those are generic terms.

Here is an example for the next person looking:

Swift:

    let params: [String: Any] = [
        "StreamSetup": [
            "Stream": "RTP-Unicast",
            "Transport": [ "Protocol": "RTSP"],
            "attributes": ["xmlns": "http://www.onvif.org/ver10/schema"]
        ],
        "ProfileToken": "profile_5"
    ]

converts into:

<StreamSetup>
    <Stream xmlns="http://www.onvif.org/ver10/schema">RTP-Unicast</Stream>
    <Transport xmlns="http://www.onvif.org/ver10/schema">
        <Protocol>RTSP</Protocol>
    </Transport>
</StreamSetup>
<ProfileToken>profile_5</ProfileToken>

I didn't need different attributes for Stream and Transport, But i was not able to figure out how to get different ones for each. It didn't matter in my case since they were the same for both.