Problem passing hash in a SOAP body

10 views
Skip to first unread message

Bryce

unread,
May 20, 2008, 11:29:17 AM5/20/08
to soap4r
Hi,

I am having some problems putting a hash into an criteria element in a
body of a SOAP request. I managed to pass in a int for another element
in the body, but I am lost on the hash. Below I copied the code, the
output, and some info from the wsdl. Sorry for the obfuscation on the
names, but its in an internal web service.

Any help or pointers in the right direction would be great.

thanks,

bryce


Code:

require 'pp'
require 'soap/wsdlDriver'
require 'soap/header/simplehandler'

#~ require 'ruby-debug'


class ClientAuthHeaderHandler < SOAP::Header::SimpleHandler

def initialize(Foo2, Foo3, Foo1, Foo10, Foo8, Foo7, Foo8)
super(XSD::QName.new("Foo.Service.LeadService", "AuthHeader"))
@Foo2 = Foo2
@Foo3= passwd
@Foo1 = Foo1
@Foo8 = Foo8
@Foo10 = Foo10
@Foo7 = Foo7
@Foo8 = Foo8
@Foo4 = 'c'
@Foo5 = 'c'
@Foo6 = 'c'
end

def on_simple_outbound
{ "Foo2" => @Foo2,
"Foo3" => @Foo3,
"Foo1" => @Foo1,
"Foo8" => @Foo8,
"Foo10" => @Foo10,
"Foo7" => @Foo7,
"Foo8" => @Foo8,
"Foo4" => @Foo4,
"Foo5" => @Foo5,
"Foo6" => @Foo6,
}
end

def on_simple_inbound(my_header, mustunderstand)
#~ @sessionid = my_header["sessionid"]
end

end


wsdl = 'http://Fooservice.test.com/FooService.asmx?wsdl'
driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
driver.wiredump_dev = STDOUT
h = ClientAuthHeaderHandler.new('test', 'test', 1, 1, 0, 123, 'test1')
driver.headerhandler << h

#pp driver.methods


#~ puts driver.methods

criteria = {:Name=> "name", :Value=>"testuser"}


criteriaLead = {}
criteriaLead[:page] = "1"
criteriaLead[:CriteriaList] = {:Criteria=> [criteria]}






Ouput:


?xml version="1.0" encoding="utf-8" ?>
<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:Header>
<n1:AuthHeader xmlns:n1="Foo.Service.LeadService"
env:mustUnderstand="0">
<n1:Foo1>1</n1:Foo1>
<n1:Foo2>test</n1:Foo2>
<n1:Foo3>test</n1:Foo3>
<n1:Foo4>c</n1:Foo4>
<n1:Foo5>c</n1:Foo5>
<n1:foo6>test1</n1:foo6>
<n1:foo8>123</n1:foo8>
<n1:Foo7>0</n1:Foo7>
<n1:Foo9>c</n1:Foo9>
<n1:Foo10>1</n1:Foo10>
</n1:AuthHeader>
</env:Header>
<env:Body>
<n2:CreateLead xmlns:n2="Foo.Service.LeadService">
<n2:page>1</n2:page>
<n2:CriteriaList>
<n2:Criteria>
</n2:Criteria>
</n2:CriteriaList>
</n2:CreateLead>
</env:Body>
</env:Envelope>

= Response

HTTP/1.1 500 Internal Server Error

Date: Tue, 20 May 2008 14:51:59 GMT

Server: Microsoft-IIS/6.0

X-Powered-By: ASP.NET

Cache-Control: private

Content-Type: text/xml; charset=utf-8

Content-Length: 428



<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/
XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Server</
faultcode><faultstring>Server was unable to process request. ---&gt;
Key cannot be null.

Parameter name: key</faultstring><detail /></soap:Fault></soap:Body></
soap:Envelope>

ignored attr: {}mixed
ignored attr: {}abstract
ignored element: {http://www.w3.org/2001/XMLSchema}anyAttribute
ignored element: {http://schemas.xmlsoap.org/wsdl/soap12/}binding
ignored element: {http://schemas.xmlsoap.org/wsdl/soap12/}operation
ignored element: {http://schemas.xmlsoap.org/wsdl/soap12/}body
ignored element: {http://schemas.xmlsoap.org/wsdl/soap12/}header
ignored element: {http://schemas.xmlsoap.org/wsdl/soap12/}address
#<SOAP::Mapping::Object:0x3518f44>: Server was unable to process
request. ---> Key cannot be null. (SOAP::FaultError)
Parameter name: key>Exit code: 1


WSDL Body:

<soap:Body>
<CreateLead xmlns="FooService.LeadService">
<page>int</page>
<CriteriaList>
<Criteria>
<Name>string</Name>
<Value>string</Value>
</Criteria>
<Criteria>
<Name>string</Name>
<Value>string</Value>
</Criteria>
</CriteriaList>
</CreateLead>
</soap:Body>
</soap:Envelope>

WSDL:

- <wsdl:types>
- <s:schema elementFormDefault="qualified"
targetNamespace="fooService.LeadService">
- <s:element name="CreateLead">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="page" type="s:int" />
<s:element minOccurs="0" maxOccurs="1" name="CriteriaList"
type="tns:ArrayOfCriteria" />
</s:sequence>
</s:complexType>
</s:element>
- <s:complexType name="ArrayOfCriteria">
- <s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="Criteria"
nillable="true" type="tns:Criteria" />
</s:sequence>
</s:complexType>
- <s:complexType name="Criteria">
- <s:complexContent mixed="false">
- <s:extension base="tns:Attribute">
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Name" type="s:string" /
>
<s:element minOccurs="0" maxOccurs="1" name="Value" type="s:string" /
>
</s:sequence>
</s:extension>

Bill Kocik

unread,
May 29, 2008, 11:00:32 AM5/29/08
to soap4r

Unless I'm really confused about what you're trying to do, the reason
your hash is showing up in the headers is simply because you're using
a header handler to inject them there. I don't really think that's
what you meant to do. I think you want to be passing the hash as an
argument to whatever method you're calling (though none of those in
the output of driver.methods look like likely candidates, and I'm not
very good at reading WSDL files yet, so I'm unsure where to steer you
exactly).

I just really don't think you want to be using a header handler to
inject the hash, because that's putting it in the headers, rather than
in the body where I think it belongs.

Hope this is somehow helpful . . .

-Bill
Reply all
Reply to author
Forward
0 new messages