Perl: SOAP::Lite

风行水上 @ 2014-02-07 23:55:45
标签:

    Basic Usage

    my $uri   = "http://service/uri" ;
    my $proxy = "https://service.provider.address/service" ;
    
    my $client = SOAP::Lite;
    
    $client->uri($uri);
    $client->proxy($proxy);
    
    $client->outputxml(1);
    
    my $param = SOAP::Data->name('item' => \SOAP::Data->value(
      SOAP::Data->name('ATTR_NAME' => $_[1]),
      SOAP::Data->name('SIGN' => 'I'),
      SOAP::Data->name('OP' => 'BT'),
      SOAP::Data->name('LOW' => $low_val),
      SOAP::Data->name('HIGH' => $high_val)))
    ); 
    
    my $xml = $client->call('some_func'=>$param);
    

    Debug

    To print out the request XML content:

    use SOAP::Lite +trace => [ transport => sub { print $_[0]->as_string } ];
    
    // my ($http_object) = @_;
    // ref($http_object) eq "HTTP::Request" || ref($http_object) eq "HTTP::Response"
    

    Demo output for a SOAP request:

    POST http://.../query HTTP/1.1
    Accept: text/xml
    Accept: multipart/*
    Content-Length: 994
    Content-Type: text/xml; charset=utf-8
    SOAPAction: ""
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope
      xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsd="http://www.w3.org/1999/XMLSchema"
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
    <namesp1:SOME_METHOD xmlns:namesp1="urn:sap-com:document:sap:rfc:functions">
    <IT_SELECTION_FIELDS/>
    <IT_SELECTION_PARAMETERS>
      <item>
        <ATTR_NAME xsi:type="xsd:string">CHANGED_AT</ATTR_NAME>
        <SIGN xsi:type="xsd:string">I</SIGN>
        <OP xsi:type="xsd:string">BT</OP>
        <LOW xsi:type="xsd:long">20131101000000</LOW>
        <HIGH xsi:type="xsd:long">20131110200000</HIGH>
      </item>
    </IT_SELECTION_PARAMETERS>
    </namesp1:SOME_METHOD>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    
    标签:

      分享到:
      comments powered by Disqus

      28/30ms