You are here iC Home > Perl > SOAP > SOAP Examples

Perl

5.3.5 SOAP Examples

08.09.2008
5.3.4 Google SOAP [  up  ] - [ a - z ] - [ search PC ] - [ top ] 5.4 eBay API

  1. Simple

    Download files/soap/wsdl dynamic1 pl.txt
    #!perl -w
    #!d:\perl\bin\perl.exe 
    
    # -- SOAP::Lite -- soaplite.com -- Copyright (C) 2001 Paul Kulchenko --
    
    BEGIN { warn "Started...\n" }
    
    # import interface. All methods from loaded service are imported by default
    use SOAP::Lite
      service => 'http://services.xmethods.net/soap/urn:xmethods-delayed-quotes.wsdl',
      # service => 'file:/your/local/path/xmethods-delayed-quotes.wsdl',
      # service => 'file:./xmethods-delayed-quotes.wsdl',
    ;
    
    warn "Loaded...\n";
    print getQuote('MSFT'), "\n";
    

    Output

    Started...
    Loaded...
    21.88
    



  2. Nested attributes

    Download files/soap/nested code pl.txt
    #!/usr/bin/perl -w
    use strict;
    
    # -- Nested attributes
    
    use SOAP::Lite;
    
    my @array = qw(11 22);
     
    my $client = SOAP::Lite
     ->readable(1)
     ->uri('http://tertius.example.com/Demo')
     ->proxy('http://localhost:7890');
     
    my $temp_elements = SOAP::Data
     ->name("CallDetails" => \SOAP::Data->value(
           SOAP::Data->name("elem1" => 'foo'),
           SOAP::Data->name("elem2" => 'baz'),
           SOAP::Data->name("someArray" => \SOAP::Data->value(
        SOAP::Data->name("someArrayItem" => @array)
           ->type("SomeObject"))
             )->type("ArrayOf_SomeObject") ))
     
     ->type("SomeObject");
     
    my $response = $client->someMethod($temp_elements); 
    

    Output

    # ... is beeing sent as followed
    
    SOAPAction: "http://tertius.example.com/Demo#someMethod"
     
    <?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope
        xmlns:namesp1="http://namespaces.soaplite.com/perl"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
     
      <soap:Body>
    
        <someMethod xmlns="http://tertius.example.com/Demo">
          <CallDetails xsi:type="namesp1:SomeObject">
    	 <elem1 xsi:type="xsd:string">foo</elem1>
    	 <elem2 xsi:type="xsd:string">baz</elem2>
    	 <someArray xsi:type="namesp1:ArrayOf_SomeObject">
    	   <someArrayItem xsi:type="namesp1:SomeObject">11</someArrayItem>
    	   <someArrayItem xsi:type="namesp1:SomeObject">22</someArrayItem>
    	 </someArray>
          </CallDetails>
        </someMethod>
    
      </soap:Body>
     
    </soap:Envelope>
    


  3. Nested attributes 2

    Download files/soap/nested code2 pl.txt
    #!/usr/bin/perl -w
    use strict;
    
    # -- Nested attributes
    
    use SOAP::Lite;
    
    my @array = qw(11 22);
     
    my $client = SOAP::Lite
    	->readable(1)
    	->uri('http://tertius.example.com/Demo')
    	->proxy('http://localhost:7890');
     
    my $temp_elements;
    my @params = ();
    
    $temp_elements = SOAP::Data
            ->name("TargetStaging" => 'foo')
            ->type("");
    push(@params, $temp_elements);
    
    $temp_elements = SOAP::Data
    	->name("CallDetails" => \SOAP::Data->value(
    		SOAP::Data->name("elem1" => 'foo'),
    		SOAP::Data->name("elem2" => 'baz'),
    		SOAP::Data->name("someArray" => \SOAP::Data->value(
    			SOAP::Data->name("someArrayItem" => @array)
    		->type("SomeObject"))
             )->type("ArrayOf_SomeObject") ))
     
    	->type("SomeObject");
    push(@params, $temp_elements);
     
    my $response = $client->someMethod(@params); 
    

    Output

    # -- ... is being sent as
    
    <?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope
        xmlns:namesp1="http://namespaces.soaplite.com/perl"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    
      <soap:Body>
    
        <someMethod xmlns="http://tertius.example.com/Demo">
    
          <TargetStaging>foo</TargetStaging>
    
          <CallDetails xsi:type="namesp1:SomeObject">
    	<elem1 xsi:type="xsd:string">foo</elem1>
    	<elem2 xsi:type="xsd:string">baz</elem2>
    
    	<someArray xsi:type="namesp1:ArrayOf_SomeObject">
    	  <someArrayItem xsi:type="namesp1:SomeObject">11</someArrayItem>
    	  <someArrayItem xsi:type="namesp1:SomeObject">22</someArrayItem>
    	</someArray>
          </CallDetails>
    
        </someMethod>
    
      </soap:Body>
    </soap:Envelope>
    

  4. Nested attributes 3

    Download files/soap/nested code3 pl.txt
    See also files/soap/nested code3mail pl.txt
    #!/usr/bin/perl -w
    use strict;
    
    # -- Nested attributes
    
    use SOAP::Lite;
    
    my @array = qw(11 22);
     
    my $client = SOAP::Lite
    	->readable(1)
    	->uri('http://tertius.example.com/Demo')
    	->proxy('http://localhost:7890');
     
    my $temp_elements;
    my @params = ();
    
    $temp_elements = SOAP::Data
            ->name("TargetStaging" => 'foo')
            ->type("");
    	push(@params, $temp_elements);
    
    $temp_elements = SOAP::Data
    	->name("Item" =>
    		\SOAP::Data->value(
    			SOAP::Data->name("type" => 'ADSL_CF_HARDWARE'),
    			SOAP::Data->name("external_id" => 4711),
    
    			SOAP::Data->name("category" =>
    				\SOAP::Data->name("name" => 'ADSL_CF'),
    			),
    
    			SOAP::Data->name("attribute" =>
    				\SOAP::Data->value(
    					SOAP::Data->name("key" => "ORDERBY"),
    					SOAP::Data->name("value" => 1)
    				)
    			),
    
    			SOAP::Data->name("attribute" =>
    				\SOAP::Data->value(
    					SOAP::Data->name("key" => "LINE_TYPE"),
    					SOAP::Data->name("value" => 'analog')
    				)
    			),
    		)
    		->type("ItemObject")
    	)
    	->type("StructureOf_Item");
    	push(@params, $temp_elements);
     
    my $response = $client->AddItemRequest(@params); 
    

    Output

    # ... is being sent as
    
    POST / HTTP/1.1
    TE: deflate,gzip;q=0.3
    Connection: TE, close
    Accept: text/xml
    Accept: multipart/*
    Accept: application/soap
    Host: localhost:7890
    User-Agent: SOAP::Lite/Perl/0.67
    Content-Length: 1149
    Content-Type: text/xml; charset=utf-8
    SOAPAction: "http://tertius.example.com/Demo#AddItemRequest"
    
    <?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope
        xmlns:namesp1="http://namespaces.soaplite.com/perl"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    
      <soap:Body>
      
        <AddItemRequest xmlns="http://tertius.example.com/Demo">
        
          <TargetStaging>foo</TargetStaging>
    
          <Item xsi:type="namesp1:StructureOf_Item">
    	<type xsi:type="xsd:string">ADSL_CF_HARDWARE</type>
    	<external_id xsi:type="xsd:int">4711</external_id>
    
    	<category>
    	  <name xsi:type="xsd:string">ADSL_CF</name>
    	</category>
    
    	<attribute>
    	  <key xsi:type="xsd:string">ORDERBY</key>
    	  <value xsi:type="xsd:int">1</value>
    	</attribute>
    
    	<attribute>
    	  <key xsi:type="xsd:string">LINE_TYPE</key>
    	  <value xsi:type="xsd:string">analog</value>
    	</attribute>
    	
          </Item>
          
        </AddItemRequest>
        
      </soap:Body>
    </soap:Envelope>
    
 
5.1   RSS 2.0
5.2   XML RPC
 5.2.1  XML::Parser
5.3   SOAP
 5.3.1  SOAP Error Handling
 5.3.2  SOAP Basic Authorization
 5.3.3  SOAP Array
 5.3.4  Google SOAP
 5.3.5  SOAP Examples
5.4   eBay API
 5.4.1  Example: get Ebay Time




See also:



Advanced search tips
5.3.4 Google SOAP [  up  ] - [ top ] 5.4 eBay API



[ home ] - [ search ] - [ feedback ]

copyright by reto - created with mytexi