I had to access a web service using SOAP. The request XML that is to be sent to a web service is a bit complex. Therefore, I got inspiration of writing this article How to Access Nested SOAP Body Element.
Solution:I had searched on the net regarding how to access Nested SOAP Body Element and I came across an article written by Byrne Reese SOAP::Lite Client HOWTO.
This article gave me some idea about how to access the nested SOAP element and after that doing many trial and run. I got the results as per my requirement. Here below I am giving the request format which, I need to generate and the code through which, I got the results.
Request Format:<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENC=http://schemas.xmlsoap.org/soap/encoding/ SOAP-
ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<Search xmlns="http://www.xyz.com/booksdata/">
<Start xsi:type="xsd:int">1</Start>
<Count xsi:type="xsd:int">10</Count>
<QueryValue>
<Items>
<QueryItem>
<Value xsi:type="xsd:string">'C++</Value>
<Field xsi:type="xsd:string">
FIELD_TITLE
</Field>
<FindOption xsi:type="xsd:string">
FIND_STARTWITH
</FindOption>
</QueryItem>
<QueryItem>
<Value xsi:type="xsd:string">"4763194097"</Value>
<Field xsi:type="xsd:string">
FIELD_ISBN
</Field>
<FindOption xsi:type="xsd:string">
FIND_EXACT
</FindOption>
</QueryItem>
</Items>
<Join xsi:type="xsd:string">CHAR_OR</Join>
</QueryValue>
</Search>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Sample Code:use SOAP::Lite;
$sBookName = 'C++';
$sIsbn = '4763194097';
$soap = SOAP::Lite
-> uri('http://www.xyz.com/booksdata/')
-> encoding('Shift_JIS')
-> on_action( sub { join '/', 'http://www. xyz.com /booksdata', $_
[1] } )
-> proxy('http:// xyz.com /booksdata/InfoSvcV02.asmx');
$method = SOAP::Data->name('Search')->attr({xmlns => 'http://www
xyz.com /booksdata/'});
@params = ( SOAP::Data->name("Start" => 0),
SOAP::Data->name("Count" => 10),
SOAP::Data->name("QueryValue"=>
\SOAP::Data->name("Items"=>
\SOAP::Data->name("QueryItem"=>
\SOAP::Data->value(SOAP::Data->name("Value" =>
$sBookName)
->type("string"),
SOAP::Data->name("Field" => "FIELD_TITLE"),
SOAP::Data->name("FindOption"
=> "FIND_STARTWITH")),
SOAP::Data->name("QueryItem"=>
\SOAP::Data->value(SOAP::Data->name("Value" =>
$sIsbn)
->type("string"),
SOAP::Data->name("Field" => "FIELD_ISBN"),
SOAP::Data->name("FindOption"
=> "FIND_EXACT")))),
SOAP::Data->name("Join"=> "CHAR_OR"))));
$result = $soap->call($method => @params);
print "Search result: ".$result->result."\n";
About the Author, Mahesh Gadwal:"I am working with manas solutions pvt. Ltd. Pune, India from last 3 and half years. After completing my Masters from Pune University, I had started my carrier with this company and right from the beginning, I worked on web related technologies. Initially I had done testing of the web sites but after some time, I shifted to development. I had developed various intranets as well as Internet applications including mobile services such as I-mode, in PHP and ASP. I had worked on various databases like SQL server, MS- Access, PostgresSQL and MySql. I had also worked on XML. Recently I worked on SOAP Lite for one of the project and where I came to know about how to access the web services. I am impressed by the concept behind the web services. In future I would like to work on developing and deploying the web services."
hi mahesh saw this comment on your soap technology too technical for me but keep up the good work.
Posted by: Narendra Nath Arora | March 02, 2004 at 11:05 PM