Hello-
I am trying to use soap4r (with wsdl2ruby generated code) to talk to my SOAP service which is written in Java and uses a schema to validate soap messages. My messages are defined in the schema as follows:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:lp="Lightpaper" targetNamespace="Lightpaper">
<xs:complexType name="login">
<xs:sequence>
<xs:element name="username" type="xs:string"/>
<xs:element name="password" type="xs:string"/>
<xs:element name="timezone" type="xs:string" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="client" type="xs:string" use="optional"/>
<xs:attribute name="version" type="xs:int" use="optional"/>
</xs:complexType>
<xs:element name="login" type="lp:login"/>
<xs:complexType name="loginResponse">
<xs:sequence>
<xs:element name="loginResult">
<xs:complexType>
<xs:sequence>
<xs:element name="sessionID" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:element name="loginResponse" type="lp:loginResponse"/>
</xs:schema>
I put this same code into the schema section of my wsdl and when I used the generated code, the message sent from soap4r looked like this:
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<login client="Lightpaper"
version="201004"
xmlns="Lightpaper">
<username>glappen</username>
<password>lightbeam</password>
</login>
</env:Body>
</env:Envelope>
And I got the following error back:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<faultcode>soapenv:Client</faultcode>
<faultstring>Element not allowed: username@Lightpaper in element login@Lightpaper</faultstring>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
which means that my service is rejecting the request because the username element in the request is in the same namespace as the login element, but according to the schema the username should be sent unqualified, which is the default value for elementFormDefault. Here is an example of a request that succeeds:
<m:login client="Lightpaper" version="201004" xmlns:m="Lightpaper">
<username>glappen</username>
<password>lightbeam</password>
<timezone>EDT</timezone>
</m:login>
Notice the difference: the login element is stillin the "Lightpaper" namespace, but the namespace has a prefix "m" in this case, which means the username, password, and timezone elements are in the global namespace, not in Lightpaper, just as you would expect with elementFormDefault="unqualified".
I tried setting elementFormDefault="unqualified" in the schema section of my wsdl, but the code sent by soap4r remained the same. Please contact me if you would like further info.
Thanks!
Greg