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

Nested Attributes #433

Closed
mcmahoniel opened this issue Apr 14, 2013 · 5 comments
Closed

Nested Attributes #433

mcmahoniel opened this issue Apr 14, 2013 · 5 comments

Comments

@mcmahoniel
Copy link

My WSDL is located at: https://gsxwsit.apple.com/wsdl/amAsp/gsx-amAsp.wsdl

I'm attempting to do the "Authenticate" request, passing along a username, password, and service account number as requested.

SoapUI works normally, giving me a token that I can use for later commands.

With Savon, I get: (S:Client) Cannot find dispatch method for {http://gsxws.apple.com/services/core/asp/am}Authenticate

It seems that Savon produces XML like this:

<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:global-rr="http://gsxws.apple.com/services/core/asp/am" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Body>
        <global-rr:Authenticate>
            <userid>test</userid>
            <password>test</password>
            <serviceaccountno>12345</serviceaccountno>
        </global-rr:Authenticate>
    </env:Body>
</env:Envelope>

but my SOAP endpoint wants it like this (from SoapUI):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:glob="http://gsxws.apple.com/elements/global">
   <soapenv:Header/>
   <soapenv:Body>
      <glob:Authenticate>
         <AuthenticateRequest>
            <userId>test</userId>
            <password>test</password>
            <serviceAccountNo>12345</serviceAccountNo>
         </AuthenticateRequest>
      </glob:Authenticate>
   </soapenv:Body>
</soapenv:Envelope>

Notice I have an extra nested attribute for "AuthenticateRequest" inside of "glob:Authenticate".

Here's my code:

wsdl = "https://gsxwsit.apple.com/wsdl/amAsp/gsx-amAsp.wsdl"
client = Savon.client do
  wsdl wsdl
end
@response = client.call(:authenticate, message: { userid: "test", password: "test", serviceaccountno: "12345" })
@rubiii
Copy link
Contributor

rubiii commented Apr 15, 2013

you have to add the AuthenticateRequest to the hash. something like this should work:

message: {
  authenticate_request: {
    user_id: "test", password: "test", service_account_no: "12345"
  }
}

ps. notice the snakecase user_id and service_account_no fields.

@mcmahoniel
Copy link
Author

Thanks for responding so quickly!

Here is the code I changed:

@response = client.call(:authenticate,  message: { authenticate_request: {  user_id: "test", password: "test", service_account_no: "12345" } })

After trying that, I get:

<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:global-rr="http://gsxws.apple.com/services/core/asp/am" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <global-rr:Authenticate>
            <authenticateRequest>
                    <userId>test</userId>
                    <password>test</password>
                    <serviceAccountNo>12345</serviceAccountNo>
            </authenticateRequest>
        </global-rr:Authenticate>
    </soapenv:Body>
</soapenv:Envelope>

which does give me the nested "AuthenticateRequest" (although the case is wrong, but I can fix that later).

Unfortunately I'm still getting
Savon::SOAPFault: (S:Client) Cannot find dispatch method for {http://gsxws.apple.com/services/core/asp/am}Authenticate

I even pasted in the full XML produced by Savon into SoapUI (with the correct capitalization) and it still returns the same error.

Here's what I figured out toying with SoapUI:

SoapUI generates

xmlns:glob="http://gsxws.apple.com/elements/global"

where Savon generates

xmlns:global-rr="http://gsxws.apple.com/services/core/asp/am"

If I submit in SoapUI the following:

<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:global-rr="http://gsxws.apple.com/elements/global" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <global-rr:Authenticate>
            <AuthenticateRequest>
                    <userId>test</userId>
                    <password>test</password>
                    <serviceAccountNo>12345</serviceAccountNo>
            </AuthenticateRequest>
        </global-rr:Authenticate>
    </soapenv:Body>
</soapenv:Envelope>

(changed the URI in xmlns:global-rr) I get the expected "Invalid User ID/Password from my SOAP service.

So it seems that Savon is pulling the wrong URI from the WSDL or I'm missing an option I need to set.

Thanks again for your help and your Gem!

EDIT:

I just set
namespace "http://gsxws.apple.com/elements/global"
in my constructor and it then correctly sets the namespace and communicates with the service.

Now all I need to do is get "authenticateRequest" to be "AuthenticateRequest" and all is well!

@rubiii
Copy link
Contributor

rubiii commented Apr 15, 2013

try the global namespace_identifier option. i'll take a look at the wsdl and why savon uses
the wrong namespace when i find some time.

edit: didn't see your "edit" ;) that should work as well.

@mcmahoniel
Copy link
Author

See the edit at the end of my comment, I was able to get the namespace set with
namespace "http://gsxws.apple.com/elements/global"
in my client constructor. My only issue now is the "authenticateRequest" token needs to be capitalized like "AuthenticateRequest" while the message body needs to be capitalized like "userId" which it already is.

Thanks for taking the time to look at this! I was beating my head against a wall all day yesterday.

EDIT:

Looks like I've got a response!

@response = client.call(:authenticate) do
  message "AuthenticateRequest" => { user_id: "test", password: "test", service_account_no: "12345" }
end

I think I can get it working from here, thanks for the assistance!

@rubiii
Copy link
Contributor

rubiii commented Apr 21, 2013

so, i used your wsdl to see why savon uses the wrong namespace and it's because the wsdl doesn't define any types
but imports various schemas instead, which wasabi does not yet follow. closing this one as there's already an issue
for this: #340.

@rubiii rubiii closed this as completed Apr 21, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants