Oops, I took a look at the Stack behind a simple question, but it's making me confused. Knowing the concept of Webservice is relatively easy, but practice is the focus of this question. I saw some other questions here, but that were not answered because of how the question was put, so I want to specify, exemplify the best possible so that they can help me.
It's easy to find Libs to develop a Webservice, the question is, can I conceptually create a Webservice without any Lib? For example, receiving the data via Post, or Get, manipulates it and return a response in Json, or XML for an application developed on a different platform? Keeping interoperability and other features of a webservice ...
As Gambiarra has done this:
<?php
include 'servidor.php';
$resposta=array();
if(isset($_GET['comando'])){
$comando=$_GET['comando'];
switch($comando){
case "Inserir":
if(isset($_GET['nome']) && isset($_GET['ra'])){
$r=inserirContato($_GET['nome'] , $_GET['ra']);
if($r){
$resposta['codigo']=1;
$resposta['mensagem']="Sucesso ao inserir!";
}else{
$resposta['codigo']=0;
$resposta['mensagem']="Erro ao inserir!";
}
}else{
$resposta['codigo']=0;
$resposta['mensagem']="Campos ausentes!";
}
break;
But I've already done this:
<?php
include 'conexao.class.php';
include 'lib/nusoap.php'; // BAIXADO DA INTERNET
$server = new nusoap_server;
$server->configureWSDL('agenda','urn:agenda');
$server->wsdl->schemaTargetNamespace='urn:agenda';
$server->wsdl->addComplexType(
'Contato',
'complexType',
'struct',
'all',
'',
array(
'id'=>array('name'=>'id','type'=>'xsd:int'),
'nome'=>array('name'=>'nome','type'=>'xsd:string'),
'telefone'=>
array('name'=>'telefone','type'=>'xsd:string')
)
);
$server->wsdl->addComplexType(
'ArrayString',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType',
'wsdl:arrayType'=>'xsd:string[]')
),
'xsd:string'
);
$server->register(
'procurarContato',
array('id'=>'xsd:int'),
array('return'=>'tns:Contato'),
'urn:agenda',
'urn:agenda#procurarContato',
'rpc',
'encoded',
'Procurar contato'
);
function procurarContato($id){
$con = new conexao();
if($con->connect()){
$query=mysql_query("SELECT * FROM contato where id='$id'");
$row = mysql_fetch_array($query);
$contatos=array(
'id'=>$row['id'],
'nome'=>$row['nome'],
'telefone'=>$row['telefone']
);
$con->disconnect();
return $contatos;
}else return null;
}
Regarding the delivery of the desired information both worked, although one I used a lib to have documentation and be something more formal and the other not. It may seem that my question is the answer itself, but then there is my doubt, these two forms above are Webservices? If not, how would you classify the first form? I can improve the issue if it seems too broad or too vague. (Remembering that the excerpts from the codes pasted here are just to illustrate the use of the library, there are still functions, parses for responses etc.