Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
SOAP: detecting nil element in the response
Mark Slater
1/3/2007 8:43:00 AM
I'm still getting used to Ruby, so there could be a very easy and
obvious answer to this one. Essentially, the server sends back nil
elements, which Ruby translates into SOAP::Mapping::Object instances.
But how do I determine when those SOAP::Mapping::Object instances
represent nil elements?
Here are the details. I'm calling a soap method to get profile
information about a user in the system I'm writing. The soap that
comes back looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="
http://schemas.xmlsoap.org/soap/envel...
xmlns:xsd="
http://www.w3.org/2001/XMLSc...
xmlns:xsi="http://
www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<getUserInformationResponse xmlns="
http://rpc.whispe...
...
<out xmlns="
http://rpc.whispe...
...
<aboutText xmlns="
http://core.whispe...
&quo... is stuff
about me.</aboutText>
<familyName xmlns="
http://core.whispe...
...Last</fami...
<firstName xmlns="
http://core.whispe...
...First</fir...
<gender xmlns="
http://core.whispe...
...0</...
<namePrefix xmlns="
http://core.whispe...
...Dr.</name...
<nameSuffix xmlns="
http://core.whispe...
...Esq</name...
<otherNames xmlns="
http://core.whispe...
&...
<previousNames xmlns="
http://core.whispe...
...
<ns1:string xmlns:ns1="http://
rpc.whisper.ucsc.edu">previous_name_1</ns1:string>
<ns1:string xmlns:ns1="http://
rpc.whisper.ucsc.edu">previous_name_2</ns1:string>
</previousNames>
</out>
</getUserInformationResponse>
</soap:Body>
</soap:Envelope>
The WSDL (auto generated by XFire) for this particular type is:
<xsd:complexType name="UserInfoData">
<xsd:sequence>
<xsd:element name="aboutText" type="xsd:string" minOccurs="0"
nillable="true"/>
<xsd:element name="familyName" type="xsd:string" minOccurs="0"
nillable="true"/>
<xsd:element name="firstName" type="xsd:string" minOccurs="0"
nillable="true"/>
<xsd:element name="gender" type="xsd:string" minOccurs="0"
nillable="true"/>
<xsd:element name="namePrefix" type="xsd:string" minOccurs="0"
nillable="true"/>
<xsd:element name="nameSuffix" type="xsd:string" minOccurs="0"
nillable="true"/>
<xsd:element name="otherNames" type="xsd:string" minOccurs="0"
nillable="true"/>
<xsd:element name="previousNames" type="tns:ArrayOfString"
minOccurs="0" nillable="true"/>
</xsd:sequence>
</xsd:complexType>
You'll notice that the otherNames element in the response is nil and
that its typed as a string in the WSDL. Users are not required to
enter any of this data, so having nil elements in the response is
valid semantically. In trying to figure out how Ruby SOAP clients
work, I'm doing the following when I get the results back:
...
results = driver.getUserInformation( :in0 => user )
puts '----- result data -----'
puts "name: #{results.out.namePrefix} #{results.out.firstName} #
{results.out.otherNames} #{results.out.familyName}, #
{results.out.nameSuffix}"
puts "gender: #{results.out.gender}"
puts "about text: #{results.out.aboutText}"
puts "first name type = #{results.out.firstName.class}"
puts "other names type = #{results.out.otherNames.class}"
puts "previous names type = #{results.out.previousNames.class}"
The output of that code gives me:
----- results -----
#<SOAP::Mapping::Object:0xa87a5a {
http://rpc.whispe...
}
out=#<SOAP::Mapping::Object:0xa87924 {
http://core.whispe...
}
aboutText="This is stuff about me." {
http://core.whispe...
}
familyName="Last" {
http://core.whispe...
}
firstName="First" {
http://core.whispe...
}gender="0" {http://
core.whisper.ucsc.edu}namePrefix="Dr." {
http://core.whispe...
}
nameSuffix="Esq" {
http://core.whispe...
}
otherNames=#<SOAP::Mapping::Object:0xa86a60> {http://
core.whisper.ucsc.edu}previousNames=#<SOAP::Mapping::Object:0xa85f84
{
http://rpc.whispe...
}string=["previous_name_1",
"previous_name_2"]>>>
----- result data -----
name: Dr. First #<SOAP::Mapping::Object:0xa86a60> Last, Esq
gender: "0"
about text: "This is stuff about me."
first name type = String
other names type = SOAP::Mapping::Object
previous names type = SOAP::Mapping::Object
Obviously if the element is assigned to an object, I can't just test
to see if its nil; I've also tried comparing it to an empty string.
Is there any way to do detect a nil element in the SOAP response?
Thanks,
Mark
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
SOAP: detecting nil element in the response
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password