Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

SOAP Server and XML

by rppowell (Novice)
on Nov 26, 2007 at 23:23 UTC ( #653121=perlquestion: print w/replies, xml ) Need Help??

rppowell has asked for the wisdom of the Perl Monks concerning the following question:

I have posted this earlier, see SOAP::Transport::HTTP::Daemon and XML, but I still need help getting SOAP::Lite to return the correct XML information.
This is for a SOAP Server, not the SOAP Client.
Here is the code for the Fake SOAP Server:
use strict; use SOAP::Lite + "trace"; use SOAP::Transport::HTTP; use Data::Dumper; my $serverinfo = { version => "0.1.dev", validTypes => [ filetype => "txt", filetype => "html", ], statistics => { documentsProcessed => 0, }, }; sub FileQueue::getServerInfo { return SOAP::Data->name( info => $serverinfo ); } my $daemon = SOAP::Transport::HTTP::Daemon -> new (LocalPort => 88) -> dispatch_to('FileQueue') ; print "Contact to SOAP server at ", $daemon->url, "\n"; $daemon->handle;
This is the XML that is generated:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/env +elope/" xmlns:namesp2="http://xml.apache.org/xml-soap" xmlns:xsi="htt +p://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENC="http://schema +s.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/1999/XMLSc +hema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encodin +g/"> <SOAP-ENV:Body> <namesp1:getServerInfoResponse xmlns:namesp1="http://www.perlmonks +.org/FileQueue"> <info xsi:type="namesp2:SOAPStruct"> <statistics xsi:type="namesp2:SOAPStruct"> <documentsProcessed xsi:type="xsd:int">0</documentsProcessed +> </statistics> <version xsi:type="xsd:string">0.1.dev</version> <validTypes xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd: +string[4]"> <item xsi:type="xsd:string">filetype</item> <item xsi:type="xsd:string">txt</item> <item xsi:type="xsd:string">filetype</item> <item xsi:type="xsd:string">html</item> </validTypes> </info> </namesp1:getServerInfoResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
I am trying to generate the following XML:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/env +elope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xm +lns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http:/ +/www.w3.org/1999/XMLSchema" xmlns:pmq="http://www.perlmonks.com/FileQ +ueue"> <SOAP-ENV:Body> <pmq:getServerInfoResponse> <info> <version>0.1.dev</version> <validTypes> <filetype>txt</filetype> <filetype>txt</filetype> </validTypes> <statistics> <documentsProcessed>0</documentsProcessed> </statistics> </info> </pmq:getServerInfoResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
How do I get it to generate the XML without the xsi:type attributes?

How do I modify the XML headers? -rppowell

Replies are listed 'Best First'.
Re: SOAP Server and XML
by erroneousBollock (Curate) on Nov 27, 2007 at 01:39 UTC
    Just reading through the SOAP::Lite gives a few pointers...

    I think you can have the "pmq" namespace registered in the SOAP Envelope by doing something like (updated):

    # add this to your service instantiation $daemon->envelope( register_ns => 'http://www.perlmonks.com/FileQueue', 'pmq'); # force the 'pmq' prefix to be used sub FileQueue::getServerInfo { return SOAP::Data->name(info => $serverinfo)->prefix('pmq'); }

    I'm not sure if that's the exact syntax but please have a play around with it (update: if that sets the 'pmq' prefix for 'info' rather than 'getServerInfoResponse', then you probably need to do something at the service level, rather than at the method level).

    I don't know how to suppress sending xsi:type attributes for elements inside the SOAP Body.
    SOAP::Lite probably allows you to do it... probably with a custom serialiser.

    -David

Re: SOAP Server and XML
by perrin (Chancellor) on Nov 26, 2007 at 23:52 UTC
      I think the OP is looking for help with method result serialisation in his SOAP::Lite server code.

      -David

Re: SOAP Server and XML
by rahed (Scribe) on Nov 27, 2007 at 16:01 UTC
    Have you tried this?

    SOAP::Data->name( info => $serverinfo )->type('');
      I've figured out how to output raw XML into the SOAP envelope: Using the same client as before: It produces the following SOAP response:
      <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instanc +e" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:S +OAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http:/ +/www.w3.org/1999/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xm +lsoap.org/soap/encoding/"> <SOAP-ENV:Body> <namesp1:getServerInfoResponse xmlns:namesp1="http://www.perlmonks +.org/FileQueue"> <info> <statistics> <documentsProcessed>0</documentsProcessed> </statistics> <validTypes> <filetype>html</filetype> <filetype>txt</filetype> </validTypes> <version>0.1.dev</version> </info> </namesp1:getServerInfoResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
      This is closer to the real SOAP server response: I am still trying to figure out how to get rid of the xmlns:namesp1="http://www.perlmonk.org/FileQueue" and the envelope headers.
        Ugh, the message was posted when I wasn't logged in.
        -rppowell
      That'd probably work for the 'info' node, but rppowell wants to (for reasons unknown) strip type attributes from all nodes descending from the Soap::Body.

      To do that, it'd need to be done either at the $daemon level, or with a custom(ised?) serialiser.

      -David

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://653121]
Approved by kvale
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2021-04-23 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?