{"id":5733,"date":"2005-06-09T23:39:12","date_gmt":"2005-06-10T07:39:12","guid":{"rendered":"http:\/\/www.ikillspies.com\/blog\/2005\/06\/09\/5733\/"},"modified":"2005-06-09T23:39:12","modified_gmt":"2005-06-10T07:39:12","slug":"soaplite-notes","status":"publish","type":"post","link":"http:\/\/www.ikillspies.com\/?p=5733","title":{"rendered":"SOAP::Lite Notes"},"content":{"rendered":"<p>Recently I&#8217;ve been playing with the perl implementation of SOAP, called SOAP::Lite.<\/p>\n<ul>\n<li>Q: There is no place in the server code that describes the tags for the response!\n<ul>\n<li>A: The article at <a href=\"http:\/\/www.majordojo.com\/soaplite\/docs\/SOAP\/Data.html\">SOAP::Data<\/a> describes how to put data into a complex type for a parameter for a method- I&#8217;m not yet certain if this works for the server side:\n<p \/>A common question is how to do you created nested XML elements using SOAP::Lite. The following example demonstrates how:<\/p>\n<pre lang='und' xml:lang='und'>    SOAP::Data-&#62;name(&#39;foo&#39; =&#62; \\SOAP::Data-&#62;value(\n        SOAP::Data-&#62;name(&#39;bar&#39; =&#62; &#39;123&#39;)));<\/pre>\n<p>The above code will produce the following XML:<\/p>\n<pre lang='und' xml:lang='und'>    &#60;foo&#62;\n      &#60;bar&#62;123&#60;\/bar&#62;\n    &#60;\/foo&#62;<\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>Q:  How do I put complex types into a SOAP::Lite?\n<ul>\n<li>A:  Again from <a href=\"http:\/\/www.majordojo.com\/soaplite\/docs\/SOAP\/Data.html#COMPLEX_TYPES\">SOAP::Data<\/a>,\n<p>The following code:<\/p>\n<pre lang='und' xml:lang='und'>    $elem1 = SOAP::Data-&#62;name(&#39;item&#39; =&#62; 123)-&#62;type(&#39;SomeObject&#39;);\n    $elem2 = SOAP::Data-&#62;name(&#39;item&#39; =&#62; 456)-&#62;type(&#39;SomeObject&#39;);\n    push(@array,$elem1);\n    push(@array,$elem2);\n\n    my $client = SOAP::Lite\n        -&#62;readable(1)\n        -&#62;uri($NS)\n        -&#62;proxy($HOST);\n\n    $temp_elements = SOAP::Data\n        -&#62;name(&#34;CallDetails&#34; =&#62; \\SOAP::Data-&#62;value(\n              SOAP::Data-&#62;name(&#34;elem1&#34; =&#62; &#39;foo&#39;),\n              SOAP::Data-&#62;name(&#34;elem2&#34; =&#62; &#39;baz&#39;),\n              SOAP::Data-&#62;name(&#34;someArray&#34; =&#62; \\SOAP::Data-&#62;value(\n                  SOAP::Data-&#62;name(&#34;someArrayItem&#34; =&#62; @array)\n                            -&#62;type(&#34;SomeObject&#34;))\n                       )-&#62;type(&#34;ArrayOf_SomeObject&#34;) ))\n\n        -&#62;type(&#34;SomeObject&#34;);\n\n    $response = $client-&#62;someMethod($temp_elements);<\/pre>\n<p>Will produce the following XML:<\/p>\n<pre lang='und' xml:lang='und'>    &#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62;\n    &#60;SOAP-ENV:Envelope\n        xmlns:xsi=&#34;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#34;\n        xmlns:SOAP-ENC=&#34;http:\/\/schemas.xmlsoap.org\/soap\/encoding\/&#34;\n        xmlns:SOAP-ENV=&#34;http:\/\/schemas.xmlsoap.org\/soap\/envelope\/&#34;\n        xmlns:xsd=&#34;http:\/\/www.w3.org\/2001\/XMLSchema&#34;\n        xmlns:namesp2=&#34;http:\/\/namespaces.soaplite.com\/perl&#34;\n        SOAP-ENV:encodingStyle=&#34;http:\/\/schemas.xmlsoap.org\/soap\/encoding\/&#34;&#62;\n      &#60;SOAP-ENV:Body&#62;\n        &#60;namesp1:someMethod xmlns:namesp1=&#34;urn:TemperatureService&#34;&#62;\n          &#60;CallDetails xsi:type=&#34;namesp2:SomeObject&#34;&#62;\n            &#60;elem1 xsi:type=&#34;xsd:string&#34;&#62;foo&#60;\/elem1&#62;\n            &#60;elem2 xsi:type=&#34;xsd:string&#34;&#62;baz&#60;\/elem2&#62;\n            &#60;someArray xsi:type=&#34;namesp2:ArrayOf_SomeObject&#34;&#62;\n              &#60;item xsi:type=&#34;namesp2:SomeObject&#34;&#62;123&#60;\/bar&#62;\n              &#60;item xsi:type=&#34;namesp2:SomeObject&#34;&#62;456&#60;\/bar&#62;\n            &#60;\/someArray&#62;\n          &#60;\/CallDetails&#62;\n        &#60;\/namesp1:test&#62;\n      &#60;\/SOAP-ENV:Body&#62;\n    &#60;\/SOAP-ENV:Envelope&#62;<\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>Q:  How do you force XML data into a response?\n<ul>\n<li>A:  there is defeinitely a nicer way to do it-  but the only way I found was to do it &#8220;manually&#8221; by force-feeding XML to SOAP::Data.  Given the XML response\n<pre>&lt;products&gt;\n  &lt;product&gt;tomatobomb&lt;\/product&gt;\n  &lt;product&gt;fishgoo&lt;\/product&gt;\n&lt;\/products&gt;<\/pre>\n<p>I used<\/p>\n<pre>sub productsList {\n  $xml_content = \"&lt;products&gt;\" .\n          \"&lt;product&gt;tomatobomb&lt;\/product&gt;\" .\n          \"&lt;product&gt;fishgoo&lt;\/product&gt;\" .\n          \"&lt;\/products&gt;\";\n  $response = SOAP::Data->type('xml' => $xml_content);\n  return $response;\n}<\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>Q:  And how do you get THAT data out?\n<ul>\n<li>A: on the client:\n<pre>$result =  $soapclient-&gt;productsList();\n  @array = $result-&gt;valueof('\/\/products\/product');\nfor my $t ( @array ) {\n        print \"node: $t \\n\";\n} <\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>Q:  How do I force XML from the client to hardcode a request?\n<ul>\n<li>A:  <\/li>\n<\/ul>\n<\/li>\n<li>Q:  What does the no-argument, &#8220;Hello World&#8221; SOAP::Lite client SOAP request look like?\n<ul>\n<li>A:  with a method &#8220;hi()&#8221; in the namespace\/service &#8220;Demo&#8221;, with no arguments:\n<pre>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;SOAP-ENV:Envelope xmlns:xsi=\"http:\/\/www.w3.org\/1999\/XMLSchema-instance\"\n    xmlns:SOAP-ENC=\"http:\/\/schemas.xmlsoap.org\/soap\/encoding\/\"\n    xmlns:SOAP-ENV=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\"\n    xmlns:xsd=\"http:\/\/www.w3.org\/1999\/XMLSchema\"\n    SOAP-ENV:encodingStyle=\"http:\/\/schemas.xmlsoap.org\/soap\/encoding\/\"&gt;\n  &lt;SOAP-ENV:Body&gt;\n    &lt;namesp1:bye xmlns:namesp1=\"Demo\"\/&gt;\n  &lt;\/SOAP-ENV:Body&gt;\n&lt;\/SOAP-ENV:Envelope&gt;<\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>Q:  What does the &#8220;Hello World&#8221; SOAP::Lite server response look like?\n<ul>\n<li>A:\n<pre>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?>\n&lt;SOAP-ENV:Envelope xmlns:xsi=\"http:\/\/www.w3.org\/1999\/XMLSchema-instance\"\n  xmlns:SOAP-ENC=\"http:\/\/schemas.xmlsoap.org\/soap\/encoding\/\"\n  xmlns:SOAP-ENV=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\"\n  xmlns:xsd=\"http:\/\/www.w3.org\/1999\/XMLSchema\"\n  SOAP-ENV:encodingStyle=\"http:\/\/schemas.xmlsoap.org\/soap\/encoding\/\"&gt;\n  &lt;SOAP-ENV:Body&gt;\n    &lt;namesp1:byeResponse xmlns:namesp1=\"Demo\"&gt;\n      &lt;s-gensym3 xsi:type=\"xsd:string\">goodbye, cruel world&lt;\/s-gensym3&gt;\n    &lt;\/namesp1:byeResponse&gt;\n  &lt;\/SOAP-ENV:Body&gt;\n&lt;\/SOAP-ENV:Envelope&gt;<\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>Q:  In SOAP::Lite, what is &#8220;namesp1&#8221;?\n<ul>\n<li>A:<\/li>\n<\/ul>\n<\/li>\n<li>Q:  How do I get my simple data out of a SOAP response in SOAP::Lite?\n<ul>\n<li>A:<\/li>\n<\/ul>\n<\/li>\n<li>Q:  How do I transport arrays through SOAP::Lite?\n<ul>\n<li>A: <\/li>\n<\/ul>\n<\/li>\n<li>Q:  How do I transport hashes through SOAP::Lite?\n<ul>\n<li>A: <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre>\n#!perl -w\nuse  SOAP::Lite;\nmy $s =  SOAP::Lite\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ->  uri('http:\/\/www.PerfectXML.com\/NETWebSvcs\/BookService')\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -> proxy('http:\/\/www.PerfectXML.NET\/WebServices\/SalesRankNPrice\/BookService.asmx')\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -> on_action(sub{sprintf '%s\/%s', @_  })\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;\n&nbsp;\nmy $ISBN =  SOAP::Data->name('ISBN' =>  1861005466)->type('string')->uri('http:\/\/www.PerfectXML.com\/NETWebSvcs\/BookService');\n$result =  $s->GetAll($ISBN)->result; # hash with elements\n&nbsp;\nprint  $result->{AmazonSalesRank}, \"\\n\";\nprint  $result->{AmazonPrice}, \"\\n\";\nprint  $result->{BNSalesRank}, \"\\n\";\nprint  $result->{BNPrice}, \"\\n\";\n<\/pre>\n<pre>\n$result =  $s->GetRate(\n&nbsp;  SOAP::Data->name('fromCurr')->type(string => $FromCode),\n&nbsp;  SOAP::Data->name('ToCurr')->type(string => $ToCode)\n)->result;\n<\/pre>\n<p>More links:<\/p>\n<pre>\nhttp:\/\/www.majordojo.com\/archives\/000042.php\nhttp:\/\/www.xav.com\/perl\/site\/lib\/SOAP\/Lite.html\nhttp:\/\/builder.com.com\/5100-6389-1045078-2.html\nhttp:\/\/users.skynet.be\/pascalbotte\/rcx-ws-doc\/soaplite.htm\nhttp:\/\/www.majordojo.com\/soaplite\/docs\/SOAP\/Data.html\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Recently I&#8217;ve been playing with the perl implementation of SOAP, called SOAP::Lite. Q: There is no place in the server code that describes the tags for the response! A: The article at SOAP::Data describes how to put data into a complex type for a parameter for a method- I&#8217;m not yet certain if this works [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-5733","post","type-post","status-publish","format-standard","hentry","category-looky"],"_links":{"self":[{"href":"http:\/\/www.ikillspies.com\/index.php?rest_route=\/wp\/v2\/posts\/5733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ikillspies.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ikillspies.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ikillspies.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ikillspies.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5733"}],"version-history":[{"count":0,"href":"http:\/\/www.ikillspies.com\/index.php?rest_route=\/wp\/v2\/posts\/5733\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.ikillspies.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ikillspies.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5733"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ikillspies.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}