wiki
Benvenuto Ospite, sei in: Login
RSS RSS

Navigazione (Tech)





Ricerca wiki
»
I Web Service di Tustena sono modulari, e a versioni.
Al momento siamo giunti alla versione 8
i web service sono nella cartella /webservice/ e più precisamente sono:
  • Catalog.asmx - per il catalogo
  • Company.asmx - per le aziende
  • Contact.asmx - per i contatti
  • Country.asmx - per i la risoluzione dei nomi delle nazioni
  • Database.asmx - per il modulo database
  • FileServer.asmx - per l'archivio e il DocGate
  • Geo.asmx - per la geo localizzazione delle aziende/contatti/lead
  • GetToken.asmx - per l'autenticazione via token
  • Lead.asmx - per i lead
  • ListManager.asmx - per la manipolazione delle liste di distribuzione
  • MailCenter.asmx - per l'invio di EMail (semplici e con allegati)
  • Order.asmx - Per il salvataggio/ricerca/modifica degli ordini (utile per l'e-commerce)
  • Report.asmx - Per l'esecuzione di report
  • TCommerce.asmx - per l'integrazione con il modulo e-Commerce


Company, Contact, Lead, e Catalog espongono 3 metodi, get; set; search; che permettono l'accesso a un DTO per lo scambio di informazioni tra le applicazioni.

Questa pagina è solo un Draft, il contenuto può essere incompleto e contenere errori.

Esempio di caricamento nuovo lead:
 csharp
// blocco di autenticazione, comune a tutti gli accessi
lead.AuthHeader auth = new lead.AuthHeader();
auth.UserName = "user@domain.it";
auth.Password = "pass";
lead.TustenaLead myLead = new TustenaLead();
myLead.AuthHeaderValue = auth;     
//now you are autenticated

//get the business object instance trough a DTO
lead.LeadDTO leadDTO = new LeadDTO();

//all the properties of lead are esposed
leadDTO.CompanyName = "test company";
leadDTO.Address = "somewhere";
leadDTO.EMail = "email";
leadDTO.ecc...

//Save the DTO to Tustena
myLead.Set(leadDTO);

Quando si esegue una ricerca con il metodo Search si deve specificare una PseudoQuery. la pseudoquery è una condizione WHERE in formato SQL che usa come colonna il nome della proprietà del DTO corrispondente.

Esempio:
 csharp
// cerca tutti i lead che cominciano per digita
long[] ids = leadDTO.Search("CompanyName like 'digita%'");
</code>

Esempio di ricerca nel modulo Database:
<code lang="cs">
DbSearchStruct[] dbs = new DbSearchStruct[1];
TustenaDatabase tb = new TustenaDatabase();
tb.AuthHeaderValue = auth;
// ottiene l'elenco dei database accessibili
DataSet databases = tb.GetDataBases();
// accede alla struttura del singolo database
DataTable dbStruct = tb.GetDatabaseStruct("Mio Database");
// inizializzo la struttura di ricerca che può essere a condizioni multiple
DbSearchStruct[] dbs = new DbSearchStruct[1];
dbs[0] = new DbSearchStruct();
dbs[0].ColumnName = "Campo 1";
dbs[0].ConditionType = TypeOfSearch.Equal;
dbs[0].ValueToSearch = "NO";
// recupera le righe che soddisfano la ricerca
DataTable resultTable = tb.Get("Mio Database", dbs);
// posso modificare la tabella a piacimento e quindi ricaricarla
tb.Set("Mio Database", resultTable );

E possibile utilizzare i Web Service anche da applicazioni create con PHP, utilizzando la libreria NuSoap. Di seguito un codice d'esempio per illustrare il metodo get.
 php
<?php 
/*NuSOAP*/
require_once('NuSOAP/lib/nusoap.php');

$login ="loginname"; // Tustena login name
$pass ="loginpwd";	// Tustena login password
$useCURL = True; // to activate in php.ini
$endpoint="http://localhost/webservice/v6/lead.asmx?wsdl"; //url of wsdl

$wsdl=true;
$client=new nusoap_client($endpoint, 'wsdl'); // instantiate the nusoap class 

$client->setCredentials($login, $pass); //submission of credentials

//error handler
	$err = $client->getError();
		if ($err) {
			echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
			echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
			exit();
		}

$client->setUseCurl($useCURL);
$client->useHTTPPersistentConnection();

// Prepare values of Lead.
$Companyid = 1; // set the id of a lead

// The exact header for the authentication
$authenticationHeader = "<AuthHeader xmlns='http://www.tustena.com/webservices/'><UserName>".$login."</UserName><Password>".$pass."</Password></AuthHeader>";
 
// Prepare the SOAP message.
$xml = '<Get xmlns="http://www.tustena.com/webservices/"><id>'.$Companyid.'</id></Get>';

//call the function to send the parameters: Get, ID Lead
$result = $client->call('Get', $xml, '', '', $authenticationHeader);
if ($client->fault) {
	// Display the fault
    echo '<p><b>Fault: ';
    print_r($result);
    echo '</b></p>';
	} 
else {
    // Check for errors
    $err = $client->getError();
    if ($err) {
		// Display the error
        echo '<p><b>Error: ' . $err . '</b></p>';
        echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
	} else {
        // Display the result
		echo "<Strong>View the result </Strong><BR>";
        print_r($result);
		}
	}
//function to implode multidimensional arrays
function r_implode( $glue, $pieces ) 
{ 
  foreach( $pieces as $r_pieces ) 
  { 
    if( is_array( $r_pieces ) ) 
    { 
      $retVal[] = r_implode( $glue, $r_pieces ); 
    } 
    else 
    { 
      $retVal[] = $r_pieces; 
    } 
  } 
  return implode( $glue, $retVal ); 
} 
//array to string
echo "<P> <B>Array to String</B><BR>";
echo r_implode( ',', $result) . "\n"; 


//foreach of the array
function parsearrray($array){
	foreach($array as $key => $value)
	{
		if(is_array($value))
		{
			parsearrray($value);
		}
		else
		{
			echo "<strong>".$key."</strong>" . ": " . $value ."<BR>"; 
		}
	}
}

echo "<P> <B>Display Foreach of the array</B><BR>";
parsearrray($result);
unset($client);
	
?>