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 above 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; #### #!/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 => 'localhost', => 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',$usrname,$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',$usrname,$passwrd) or die "Failed to connect to database: " . DBI->errstr; my $sth = $dbh->prepare('SELECT * FROM todo WHERE user = ? AND date = ?') 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','$usrname','$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"; } #### #!/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=; chomp $acro; print "Enter Time(YYYY-MM-DD-hr:MM)\n"; my $time=; chomp $time; print "Enter a text to your ToDoList\n"; my $text=; chomp $text; print "Enter The Priority your ToDoList(1-10)\n"; my $prio=; 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("priority")->value("$prio") ) ); #### #!/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=; chomp $acro; print "Enter the ID\n"; my $id=; chomp $id; my $data = $thay->call( deleteTodo=>( SOAP::Data->name("acronym")->value("$acro"), SOAP::Data->name("id")->value("$id") ) ); #### #!/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=; chomp $acro; my $data =$thay->call( getTodoList=>( SOAP::Data->name("acronym")->value("$acro") ) ); #### #!/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=; chomp $acro; print "Enter ID\n"; my $id=; chomp $id; print "Enter updated Time(YYYY-MM-DD-hr:MM)\n"; my $time=; chomp $time; print "Enter a updated text to your ToDoList\n"; my $text=; chomp $text; print "Enter The new Priority your ToDoList(1-10)\n"; my $prio=; 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") ) );