Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Any SOAP::Lite examples on update/insert?

by Anonymous Monk
on Jul 17, 2015 at 18:25 UTC ( [id://1135204]=perlquestion: print w/replies, xml ) Need Help??

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

Hi everyone,

I'm trying to see if there are any examples out there on SOAP::Lite that illustrate how to update or insert data into the web service. Everything I've found so far, and on http://search.cpan.org/~phred/SOAP-Lite-1.14/lib/SOAP/Lite.pm , it just shows how to query. Can we push data back to the service?

If not, is there another module that uses a WSDL and can insert/update?
  • Comment on Any SOAP::Lite examples on update/insert?

Replies are listed 'Best First'.
Re: Any SOAP::Lite examples on update/insert?
by thanos1983 (Parson) on Jul 17, 2015 at 18:51 UTC

    Hello Anonymous,

    What do you mean by:

    I'm trying to see if there are any examples out there on SOAP::Lite that illustrate how to update or insert data into the web service.

    From DEFAULT SETTINGS of the SOAP::Lite module.

    If you wish to provide common proxy() or uri() settings for all SOAP::Lite objects in your application you may do:

    use SOAP::Lite proxy => 'http://localhost/cgi-bin/soap.cgi', uri => 'http://my.own.com/My/Examples'; my $soap1 = new SOAP::Lite; # will get the same proxy()/uri() as abo +ve print $soap1->getStateName(1)->result; my $soap2 = SOAP::Lite->new; # same thing as above print $soap2->getStateName(2)->result; # or you may override any settings you want my $soap3 = SOAP::Lite->proxy('http://localhost/'); print $soap3->getStateName(1)->result;

    Any SOAP::Lite properties can be propagated this way. Changes in object copies will not affect global settings and you may still change global settings with SOAP::Lite->self call which returns reference to global object. Provided parameter will update this object and you can even set it to undef:

    SOAP::Lite->self(undef);

    There is also simple basic tutorial if you want to take a look here SOAP::Lite for Perl, with code samples.

    Update: Based on your update:

    If not, is there another module that uses a WSDL and can insert/update?

    I also found this SOAP, WSDL, XML service/client relative question that on the forum that might give one or several answer(s) to your question(s).

    Update 2: I found a server and client script that I wrote about 3-4 years ago. I think it does still work. I do not have the time to tested but I remember that was working before. I think it is just what you ask.

    Server side:

    #!/usr/bin/perl #SOAP SERVER use DBI; use strict; use warnings; use SOAP::Lite; use SOAP::Transport::HTTP; my $daemon = SOAP::Transport::HTTP::Daemon->new(LocalAddr => 'localhos +t', => LocalPort => 9005,Reuse=>1); $daemon->dispatch_to('Todo'); print "Contact to SOAP server at ", $daemon->url, "\n"; $daemon->handle(); package Todo; my $usrname = 'student'; my $passwrd = '1qaz2wsx'; #geToDoList Method sub getTodoList{ print "getToDoList method invoked by client \n"; my ($method,$acronym) = @_; my $dbh = DBI->connect('DBI:mysql:organize:localhost:9005',$usrnam +e,$passwrd) or die "Failed to connect to database: " . DBI->errstr; my $sth = $dbh->prepare('SELECT * FROM todo WHERE user = ?') or die "Couldn't prepare statement: " . $dbh->errstr; my @toDoDataArray; $sth->execute($acronym) or die "Couldn't execute statement: " . $sth->errstr; my @my_array; while (@toDoDataArray = $sth->fetchrow_array()) { my $response = SOAP::Data->name( "getTodoListResponse" => \SOAP::Data->value( SOAP::Data->name( "getTodoListResult" => \SOAP::Data->value( SOAP::Data->name( "TodoData"=>\SOAP::Data->value( SOAP::Data->name('user' => $toDoDataArray[4]), SOAP::Data->name('date' => $toDoDataArray[2]), SOAP::Data->name('note' => $toDoDataArray[1]), SOAP::Data->name('prio' => $toDoDataArray[3]), SOAP::Data->name('id' => $toDoDataArray[0]) ) ) ) ) ) ); push (@my_array,$response); } $dbh->disconnect(); return @my_array; } #getTodoOneDay Method sub getTodoOneDay{ print "getTodoOneDay method invoked by client \n"; my ($method,$acronym,$date) = @_; my $dbh = DBI->connect('DBI:mysql:organize:localhost:9005',$usrnam +e,$passwrd) or die "Failed to connect to database: " . DBI->errstr; my $sth = $dbh->prepare('SELECT * FROM todo WHERE user = ? AND dat +e = ?') or die "Failed to prepare statement: " . $dbh->errstr; my @toDoDataArray; $sth->execute($acronym,$date) or die "Failed to execute statement: " . $sth->errstr; my @my_array; while (@toDoDataArray = $sth->fetchrow_array()) { my $response = SOAP::Data->name( "getTodoListResponse" => \SOAP::Data->value( SOAP::Data->name( "getTodoListResult" => \SOAP::Data->value( SOAP::Data->name( "TodoData"=>\SOAP::Data->value( SOAP::Data->name('user' => $toDoDataArray[4]), SOAP::Data->name('date' => $toDoDataArray[2]), SOAP::Data->name('note' => $toDoDataArray[1]), SOAP::Data->name('prio' => $toDoDataArray[3]), SOAP::Data->name('id' => $toDoDataArray[0]) ) ) ) ) ) ); push (@my_array,$response); } $dbh->disconnect(); return @my_array; } #createToDo Method sub createTodo{ print "createToDo method invoked by client \n"; my ($method,$acronym,$date,$note,$priority,$id) = @_; my $dbh = DBI->connect('DBI:mysql:organize:localhost:9005','root', +'jimma1503') or die "Failed connect to database: " . DBI->errstr; my $query="INSERT INTO todo (id,note,date,prio,user) VALUES ('$id' +,'$note','$date','$priority','$acronym')"; my $sth = $dbh->prepare($query) || die "prepare: $query: $DBI::errstr"; $sth->execute || die "execute: $query: $DBI::errstr"; $dbh->disconnect(); return "INSERTED"; } #deletetodo Method sub deleteTodo { print "deleteToDo method invoked by client \n"; my($method,$acronym,$id)=@_; my $dbh = DBI->connect('DBI:mysql:organize:localhost:9005','root', +'jimma1503') or die "Failed to connect to database: " . DBI->errstr; my $sth = $dbh->prepare("DELETE FROM todo WHERE user = ? AND id=?" +); $sth->execute($acronym,$id ) or die $DBI::errstr; $sth->finish(); $dbh->disconnect(); return "DELETED"; } #updateTodo Method sub updateTodo { print "updateTodo method invoked by client \n"; my($method,$acronym,$time,$note,$priority,$id)=@_; my $dbh = DBI->connect('DBI:mysql:organize:localhost:9002','$usrna +me','$password') or die "Failed to connect to database: " . DBI->errstr; my $sth = $dbh->prepare( 'UPDATE todo SET user=?, date=?, note=?, +prio=? WHERE id=?' ); $sth->execute($acronym,$time,$note,$priority,$id) or die ( "Error on UPDATE: $DBI::errstr\n" ); $sth->finish(); $dbh->disconnect(); return "UPDATED"; }

    Client createtodo:

    #!/usr/bin/perl use strict 'vars'; #this is to protect unquotted string,bareword which + come from Soap trace use warnings; use SOAP::Lite + trace; my $thay =SOAP::Lite->new(); $thay->proxy('http://localhost:9002'); $thay->uri('Todo'); print "Enter Your Acronym:\n"; my $acro=<STDIN>; chomp $acro; print "Enter Time(YYYY-MM-DD-hr:MM)\n"; my $time=<STDIN>; chomp $time; print "Enter a text to your ToDoList\n"; my $text=<STDIN>; chomp $text; print "Enter The Priority your ToDoList(1-10)\n"; my $prio=<STDIN>; chomp $prio; my $data =$thay->call( createTodo=>( SOAP::Data->name("acronym")->value("$acro"),SOAP::Data->name("time +")->value("$time"), SOAP::Data->name("note")->value("$text"),SOAP::Data->name("priorit +y")->value("$prio") ) );

    Client deletetodo:

    #!/usr/bin/perl use strict 'vars'; #this is to protect unquotted string,bareword which + come from Soap trace use warningns; use SOAP::Lite +trace; my $thay =SOAP::Lite->new(); $thay->proxy('http://localhost:9002'); $thay->uri('Todo'); print "Enter Your Acronym to be Deleted:\n"; my $acro=<STDIN>; chomp $acro; print "Enter the ID\n"; my $id=<STDIN>; chomp $id; my $data = $thay->call( deleteTodo=>( SOAP::Data->name("acronym")->value("$acro"), SOAP::Data->name("id")->value("$id") ) );

    Client gettodolist:

    #!/usr/bin/perl #getTodoList use strict 'vars'; #this is to protect unquotted string,bareword which + come from Soap trace use warnings; use SOAP::Lite +trace; my $thay =SOAP::Lite->new(); $thay->proxy('http://localhost:9002'); $thay->uri('Todo'); print "Enter an Acronym to get list of the ToDolist:\n"; my $acro=<STDIN>; chomp $acro; my $data =$thay->call( getTodoList=>( SOAP::Data->name("acronym")->value("$acro") ) );

    Client updatetodo:

    #!/usr/bin/perl #updateTdo use warnings; use strict 'vars';#this is to protect unquotted string,bareword which +come from Soap trace use SOAP::Lite +trace; my $thay =SOAP::Lite->new(); $thay->proxy('http://localhost:9002'); $thay->uri('Todo'); print "Enter Your to Update Acronym:\n"; my $acro=<STDIN>; chomp $acro; print "Enter ID\n"; my $id=<STDIN>; chomp $id; print "Enter updated Time(YYYY-MM-DD-hr:MM)\n"; my $time=<STDIN>; chomp $time; print "Enter a updated text to your ToDoList\n"; my $text=<STDIN>; chomp $text; print "Enter The new Priority your ToDoList(1-10)\n"; my $prio=<STDIN>; chomp $prio; my $data = $thay->call( updateTodo=>( SOAP::Data->name("acronym")->value("$acro"), SOAP::Data->name("time")->value("$time"), SOAP::Data->name("note")->value("$text"), SOAP::Data->name("priority")->value("$prio"), SOAP::Data->name("id")->value("$id") ) );

    Again, in the past this code use to work, I do not have the time to debug it or test it (sorry).

    Hope this helps.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
Re: Any SOAP::Lite examples on update/insert?
by GotToBTru (Prior) on Jul 17, 2015 at 18:55 UTC

    I wonder if this might help you. I'm no expert on SOAP but executing any kind of sql on a remote database would be done the same, as I understand it. You just send a message that tells it what sql to execute, whether it's a select, update or insert.

    Dum Spiro Spero
A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-23 22:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found