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

Improve documentation on custom attributes #151

Open
felipeferri opened this issue Feb 4, 2017 · 2 comments
Open

Improve documentation on custom attributes #151

felipeferri opened this issue Feb 4, 2017 · 2 comments

Comments

@felipeferri
Copy link

felipeferri commented Feb 4, 2017

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
Copy link
Owner

priore commented Feb 6, 2017

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

@rajkhatri
Copy link

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.

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

3 participants