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

"xsi:type" value for Complex Types in return value not rendered as per generated WSDL #76

Closed
karthik-sethuraman opened this issue Dec 19, 2012 · 2 comments

Comments

@karthik-sethuraman
Copy link

Hi,

Here is an simple example code to illustrate my problem

    soap_action "getAllUsers",
              :args => nil,
              :return => {:users=>[UserInfo]},
              :to => :get_all_users
    def get_all_users
        render :soap => {:users=>[
                              {:user_id=>"user1",
                               :home_address=>{:street=>"123, abc road", :city=>"Ashburn"},
                               :work_address=>{:street=>"456, def road", :city=>"Herndon"}},
                              {:user_id=>"user2",
                               :home_address=>{:street=>"789, geh road", :city=>"Reston"},
                               :work_address=>{:street=>"456, def road", :city=>"Herndon"}}
                             ]}
    end

    class UserInfo < WashOut::Type
         map :user_id => :string,
             :home_address => Address,
             :work_address => Address
    end

    class Address < WashOut::Type
        map :street => :string,
            :city => :string
    end

Generated WSDL Snippet

         <xsd:complexType name="userInfo">
            <xsd:sequence>
               <xsd:element type="xsd:string" name="userId"/>
               <xsd:element type="tns:address" name="workAddress"/>
               <xsd:element type="tns:address" name="homeAddress"/>
            </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="address">
            <xsd:sequence>
               <xsd:element type="xsd:string" name="street"/>
               <xsd:element type="xsd:string" name="city"/>
            </xsd:sequence>
         </xsd:complexType>
         ......
         ......
      <operation name="getAllUsers">
         <input message="tns:getAllUsers"/>
         <output message="tns:getAllUsersResponse"/>
      </operation>
         ......
         ......
      <message name="getAllUsers"/>
      <message name="getAllUsersResponse">
         <part type="tns:userInfo" xsi:minOccurs="0" name="users" xsi:maxOccurs="unbounded"/>
      </message>

Rendered XML Response

     <soap:Body>
      <tns:getAllUsersResponse>
         <users xsi:type="tns:users">
            <workAddress xsi:type="tns:workAddress">
               <street xsi:type="xsd:string">456 def road</street>
               <city xsi:type="xsd:string">Herndon</city>
            </workAddress>
            <userId xsi:type="xsd:string">user1</userId>
            <homeAddress xsi:type="tns:homeAddress">
               <street xsi:type="xsd:string">123, abc road</street>
               <city xsi:type="xsd:string">Ashburn</city>
            </homeAddress>
         </users>
         <users xsi:type="tns:users">
            <workAddress xsi:type="tns:workAddress">
               <street xsi:type="xsd:string">456 def road</street>
               <city xsi:type="xsd:string">Herndon</city>
            </workAddress>
            <userId xsi:type="xsd:string">user2</userId>
            <homeAddress xsi:type="tns:homeAddress">
               <street xsi:type="xsd:string">789, geh road</street>
               <city xsi:type="xsd:string">Reston</city>
            </homeAddress>
         </users>
      </tns:getAllUsersResponse>
     </soap:Body>

As you can see the values for following xsi:type are rendered wrongly
tns:user instead of tns:userInfo
tns:homeAddress instead of tns:address
tns:workAddress instead of tns:address

Am I doing something wrong or is this a bug?

Thank You very much

Regards
Karthik

@jancel
Copy link

jancel commented Mar 13, 2013

It looks like Address (both work and home) are the same type tns:address in your wsdl. The attribute names are workAddress and homeAddress. The type, properly defined in the wsdl is Address. A consumer would properly map this to myUser1.homeAddress.street and myUser1.workAddress.street.

Is there a particular consumer giving you problems (Java introspection, .Net, SoapUI)? I have to get better at reading wsdls, but what you have looks as if it would work in Java and SoapUI.

tns:users is a variable name, not the type, in your case this is an array of UserInfo. The WSDL is responsible for telling your cliient this. Each work address, home address and user id is a type UserInfo as defined in the WSDL.

<part type="tns:userInfo" xsi:minOccurs="0" name="users" xsi:maxOccurs="unbounded"/>

Notice the TYPE definition there is userInfo. Your consumer will reference this to determine the proper consumption of the data you provided. The name matches the variable name in your provider. You can change this name, I believe it's entirely up to you.

If you introspect and consume your wsdl, there would be 2 types (UserInfo and Address). users is an array of UserInfo. In Java, if I were to dynamically introspect and consume this service, I could access everything programmatic like this.

--Pseudo
response = execute_service
for (user in response.users)
// user is of Type UserInfo
// user.workAddress is of type Address
// user.homeAddress is of type Address
user.workAddress.street; // would do something with the users work street
// user.userId is a string attribute on UserInfo type

This is just as you have defined it in your WashOut::Types.

-- If this is too winded or repetitive, I apologize. It does look like it is working as intended based on inspection of code, and wsdl. To me.

@inossidabile
Copy link
Owner

@jancel is absolutely right. That's exactly how things work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants