in reply to Re: Help getting started with SOAP
in thread Help getting started with SOAP

Am I in the right direction ?
#!/usr/bin/perl -w use strict; use LWP::UserAgent; use HTTP::Request; my $message = '<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/en +velope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http +://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <ns1:searchEstablishments soapenv:encodingStyle="http://schem +as.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:ccc-search"> <searchRequest href="#id0"/> </ns1:searchEstablishments> <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="ht +tp://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:SearchRequest" + xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2= +"http://request.services.ccc.imbs.strategis.ic.gc.ca"> <docsPage href="#id1">2</docsPage> <docsPerPage href="#id2">25</docsPerPage> <entityServiceCode xsi:type="soapenc:string">ES</entitySer +viceCode> <language xsi:type="soapenc:string">eng</language> <maxResults href="#id3">200</maxResults> <remoteBusinessPartner xsi:type="soapenc:string">xxx</remo +teBusinessPartner> <remotePassword xsi:type="soapenc:string">xxx</remotePassw +ord> <remoteServerAddress xsi:type="soapenc:string">xxx</remote +ServerAddress> <searchCriteria href="#id4"/> <strategisPassword xsi:type="soapenc:string" xsi:nil="true +"/> <strategisUserName xsi:type="soapenc:string" xsi:nil="true +"/> </multiRef> <multiRef id="id3" soapenc:root="0" soapenv:encodingStyle="ht +tp://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soa +penc="http://schemas.xmlsoap.org/soap/encoding/">100</multiRef> <multiRef id="id4" soapenc:root="0" soapenv:encodingStyle="ht +tp://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:SearchCriteria +Bean" xmlns:ns3="http://model.services.ccc.imbs.strategis.ic.gc.ca" x +mlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> <areaServed xsi:type="ns4:ArrayOf_xsd_string" xsi:nil="tru +e" xmlns:ns4="urn:ccc-search"/> <budget xsi:type="ns5:ArrayOf_xsd_string" xsi:nil="true" x +mlns:ns5="urn:ccc-search"/> <coAnlTotSlsCd xsi:type="ns6:ArrayOf_xsd_string" xsi:nil=" +true" xmlns:ns6="urn:ccc-search"/> <coAnlXprtSlsCd xsi:type="ns7:ArrayOf_xsd_string" xsi:nil= +"true" xmlns:ns7="urn:ccc-search"/> <coCageCd xsi:type="soapenc:string" xsi:nil="true"/> <coDandBNo xsi:type="soapenc:string" xsi:nil="true"/> <coDandBSfx xsi:type="soapenc:string" xsi:nil="true"/> <coPrdctNm xsi:type="soapenc:string" xsi:nil="true"/> <coTypCd xsi:type="ns8:ArrayOf_xsd_string" xsi:nil="true" +xmlns:ns8="urn:ccc-search"/> <coXprtgActvIntInd xsi:type="soapenc:string" xsi:nil="true +"/> <coXprtrInd xsi:type="soapenc:string" xsi:nil="true"/> <column xsi:type="soapenc:string">nm</column> <companyProfile xsi:type="soapenc:string" xsi:nil="true"/> <conceptOperator xsi:type="soapenc:string">and</conceptOpe +rator> <estblmtCdaEmpCnt xsi:type="ns9:ArrayOf_xsd_string" xsi:ni +l="true" xmlns:ns9="urn:ccc-search"/> <estblmtCtyNm xsi:type="soapenc:string" xsi:nil="true"/> <estblmtNm xsi:type="soapenc:string" xsi:nil="true"/> <estblmtPstlZipCd xsi:type="soapenc:string" xsi:nil="true" +/> <fscCode xsi:type="soapenc:string" xsi:nil="true"/> <hitsPerPage xsi:type="soapenc:string">250</hitsPerPage> <indusCd xsi:type="ns10:ArrayOf_xsd_string" xsi:nil="true" + xmlns:ns10="urn:ccc-search"/> <indusCdNm xsi:type="soapenc:string" xsi:nil="true"/> <isSummaryOn xsi:type="soapenc:string" xsi:nil="true"/> <isoCntryNo xsi:type="ns11:ArrayOf_xsd_string" xsi:nil="tr +ue" xmlns:ns11="urn:ccc-search"/> <isoProvSteCd xsi:type="ns12:ArrayOf_xsd_string" xsi:nil=" +true" xmlns:ns12="urn:ccc-search"/> <jcoNo xsi:type="soapenc:string" xsi:nil="true"/> <niinCode xsi:type="soapenc:string" xsi:nil="true"/> <nsnCode xsi:type="ns13:ArrayOf_xsd_string" xsi:nil="true" + xmlns:ns13="urn:ccc-search"/> <numberOfDocumentsReturned xsi:type="soapenc:string">100</ +numberOfDocumentsReturned> <numberOfMembers xsi:type="ns14:ArrayOf_xsd_string" xsi:ni +l="true" xmlns:ns14="urn:ccc-search"/> <numberOfVolunteers xsi:type="ns15:ArrayOf_xsd_string" xsi +:nil="true" xmlns:ns15="urn:ccc-search"/> <orgFocus xsi:type="ns16:ArrayOf_xsd_string" xsi:nil="true +" xmlns:ns16="urn:ccc-search"/> <organizationType xsi:type="soapenc:string" xsi:nil="true" +/> <portal xsi:type="soapenc:string" xsi:nil="true"/> <prdctCtgryCd xsi:type="ns17:ArrayOf_xsd_string" xsi:nil=" +true" xmlns:ns17="urn:ccc-search"/> <provSteShrtNm xsi:type="ns18:ArrayOf_xsd_string" xsi:nil= +"true" xmlns:ns18="urn:ccc-search"/> <qltyCrtftnShrtDesc xsi:type="ns19:ArrayOf_xsd_string" xsi +:nil="true" xmlns:ns19="urn:ccc-search"/> <sctrCd xsi:type="ns20:ArrayOf_xsd_string" xsi:nil="true" +xmlns:ns20="urn:ccc-search"/> <sectorFocus xsi:type="ns21:ArrayOf_xsd_string" xsi:nil="t +rue" xmlns:ns21="urn:ccc-search"/> <sortSpec xsi:type="soapenc:string">coid asc</sortSpec> <strategicAlliances xsi:type="ns22:ArrayOf_xsd_string" xsi +:nil="true" xmlns:ns22="urn:ccc-search"/> <subPortal xsi:type="soapenc:string" xsi:nil="true"/> <tagId xsi:type="ns23:ArrayOf_xsd_string" xsi:nil="true" x +mlns:ns23="urn:ccc-search"/> <textField xsi:type="soapenc:string">business</textField> <unspscCodeText xsi:type="soapenc:string" xsi:nil="true"/> </multiRef> <multiRef id="id2" soapenc:root="0" soapenv:encodingStyle="ht +tp://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soa +penc="http://schemas.xmlsoap.org/soap/encoding/">10</multiRef> <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="ht +tp://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soa +penc="http://schemas.xmlsoap.org/soap/encoding/">1</multiRef> </soapenv:Body> </soapenv:Envelope>'; my $userAgent = LWP::UserAgent->new(); my $request = HTTP::Request->new(GET => 'https://xxx'); $request->header(SOAPAction => 'https://xxx'); $request->content($message); $request->content_type("text/xml; charset=utf-8"); my $response = $userAgent->request($request); if($response->code == 200) { print $response->as_string; } else { print $response->error_as_HTML; }

Replies are listed 'Best First'.
Re^3: Help getting started with SOAP
by psini (Deacon) on May 29, 2008 at 13:10 UTC

    I should say so. Some points:

    You could use SOAP::Lite module, which act as a wrapper around HTTP and SOAP protocols and can simplify the last part of the script. As I said earlier I personally don't use this module since 2002, so I can't be of much help here

    You should use a XML serializer to build the request packet (I myself use XML::Writer) so that it is its responsability ensure the syntactical correctness of the XML stream (tag matching, escaping, an so on)

    You said that your service require authentication, but I can't see a header tag in your envelope...

    Rule One: Do not act incautiously when confronting a little bald wrinkly smiling man.