MercatorWebService client op basis van het .NET-framework 4.0

0000002265     -      24-06-2016

Dit voorbeeld toont hoe je een SOAP-client maakt op basis van het .NET-framework 4.0 en gebruikmakend van deMercatorWebService. Dit voorbeeld is onderworpen aan volgende regels:

  • Het wordt geleverd als "as-is" en zonder support
  • Het moet exception-handeling bevatten (try-catch-finally) om te voorkomen dat de webservice niet meer beschikbaar zou zijn.

Vooraleer je een webservice kan gebruiken, moet men, in Visual Studio verwijzen naar de service. Dit kan gedaan worden via rechtsklik op "References" en selecteer "Add reference". In de zone "Adres", moet men het volgende invullen http://testws.mercator.eu/MercatorWebService.asmx (adaptée en fonction de votre domaine). In ons voorbeeld hebben we de namespace aangepast naar "MercatorWebService40".

mercatorwebserviceclient40

Opmerking: als na het ontvangen van een antwoord, een exception wordt opgeroepen en geeft een error-message (body of message), tijdens déserialisatie, volstaaat het om de waarde te verhogen van de parameters in het bestand app.config (of web.config indien uw applicatie een ASP.NET-applicatie is) (waarden ter informatie)

  • maxBufferSize="655360"
  • maxReceivedMessageSize="655360"
  • maxNameTableCharCount="163840"

 


 

Aanmaken van een factuur in het journaal Factu:

Zoom
 MercatorWebService40.MercatorWebServiceSoapClient client = new MercatorWebService40.MercatorWebServiceSoapClient();
 MercatorWebService40.SecurityInfo si = new MercatorWebService40.SecurityInfo();
 si.SecureKey = ... ;

 MercatorWebService40.StringMws s = client.BillingEngineInitNew(si, MercatorWebService40.TypeVAEnum.V, 1, "Factu");
 if (!string.IsNullOrEmpty(s.LastError))
 {
     MessageBox.Show("BillingEngineInitNew : " + s.LastError);
     return;
 }
 // à partir d'ici, il est obligatoire d'appeler la méthode BillingEngineClose
 string uniqueId = s.Value;

 MercatorWebService40.BooleanMws b = client.BillingEngineApplyCustomerSupplier(uniqueId, "INEO52209");
 if (!string.IsNullOrEmpty(b.LastError))
 {
     MessageBox.Show("ApplyCustomerSupplier : " + b.LastError);
 }
 else
 {
     MercatorWebService40.Int32Mws i = client.BillingEngineAppendLine(uniqueId);
     if (!string.IsNullOrEmpty(i.LastError))
     {
         MessageBox.Show("BillingEngineAppendLine : " + i.LastError);
     }
     else
     {
         b = client.BillingEngineInsertItem2(uniqueId, "03102001", i.Value, 5); // q = 5
         if (!string.IsNullOrEmpty(b.LastError))
         {
             MessageBox.Show("InsertItem : " + b.LastError);
         }
         else
         {
             b = client.BillingEngineUpdateAmounts(uniqueId);
             if (!string.IsNullOrEmpty(b.LastError))
             {
                 MessageBox.Show("BillingEngineUpdateAmounts : " + b.LastError);
             }
             else
             {
                 b = client.BillingEngineSave(uniqueId);
                 if (!string.IsNullOrEmpty(b.LastError))
                 {
                     MessageBox.Show("BillingEngineSave : " + b.LastError);
                 }
                 else
                 {
                     MercatorWebService40.Int64Mws p = client.BillingEngineSavedNumber(uniqueId);
                     if (!string.IsNullOrEmpty(p.LastError))
                         MessageBox.Show("BillingEngineSavedNumber : " + p.LastError);
                     else
                         MessageBox.Show(string.Format("La vente {0} {1} a été créée !", "Factu", p.Value));
                 }
             }
         }
     }
 }
 MercatorWebService40.VoidMws v = client.BillingEngineClose(uniqueId); // toujours terminer par BillingEngineClose() après un InitNew fructueux
 if (!string.IsNullOrEmpty(v.LastError))
     MessageBox.Show("BillingEngineClose : " + v.LastError);

 


 

Een bestaande factuur wijzigen in het journaal Factu:

Zoom
MercatorWebService40.MercatorWebServiceSoapClient client = new MercatorWebService40.MercatorWebServiceSoapClient();
MercatorWebService40.SecurityInfo si = new MercatorWebService40.SecurityInfo();
si.SecureKey = ... ;

MercatorWebService40.StringMws s = client.BillingEngineInitExisting(si, MercatorWebService40.TypeVAEnum.V, 1, "00F384F9FE", "Factu", 201300003);
if (!string.IsNullOrEmpty(s.LastError))
{
    MessageBox.Show("BillingEngineInitExisting : " + s.LastError);
    return;
}
// à partir d'ici, il est obligatoire d'appeler la méthode BillingEngineClose
string uniqueId = s.Value;

MercatorWebService40.DataSetMws ds = client.BillingEngineDataSet(uniqueId);
if (!string.IsNullOrEmpty(ds.LastError))
{
    MessageBox.Show("BillingEngineDataSet : " + s.LastError);
}
else
{
    MercatorWebService40.BooleanMws b = client.BillingEngineUpdateLigne(uniqueId, 0, "pu", 100); // changer le prix unitaire sur la ligne 0
    if (!string.IsNullOrEmpty(b.LastError))
    {
        MessageBox.Show("BillingEngineUpdateLigne : " + b.LastError);
    }
    else
    {
        b = client.BillingEngineUpdateAmounts(uniqueId);
        if (!string.IsNullOrEmpty(b.LastError))
        {
            MessageBox.Show("BillingEngineUpdateAmounts : " + b.LastError);
        }
        else
        {
            MercatorWebService40.DataTableMws dt = client.BillingEnginePIEDS(uniqueId);
            if (!string.IsNullOrEmpty(dt.LastError))
            {
                MessageBox.Show("BillingEnginePIEDS : " + dt.LastError);
            }
            else
            {
                double tot_ttc_dv = Convert.ToDouble(dt.Value.Rows[0]["TOT_TTC_DV"]);

                b = client.BillingEngineSave(uniqueId);
                if (!string.IsNullOrEmpty(b.LastError))
                    MessageBox.Show("BillingEngineSave : " + b.LastError);
                else
                    MessageBox.Show(string.Format("Le nouveau total est {0:### ##0.00} !", tot_ttc_dv));
            }
        }
    }
}
MercatorWebService40.VoidMws v = client.BillingEngineClose(uniqueId);  // toujours terminer par BillingEngineClose() après un InitExisting fructueux, sinon ce document sera non modifiable dans Mercator car en cours de modification
if (!string.IsNullOrEmpty(v.LastError))
    MessageBox.Show("BillingEngineClose : " + v.LastError);

 


 

Een DataTable verkrijgen, met hierin de eerste klant:

Zoom
MercatorWebService40.MercatorWebServiceSoapClient client = new MercatorWebService40.MercatorWebServiceSoapClient();
MercatorWebService40.SecurityInfo si = new MercatorWebService40.SecurityInfo();
si.SecureKey = ... ;
MercatorWebService40.DataSetMws ds = client.Zselect(si, "select top 1 * from cli");
if (!string.IsNullOrEmpty(ds.LastError))
{
    MessageBox.Show("Zselect : " + ds.LastError);
    return;
}
DataTable dt_cli1 = ds.Value.Tables[0];

 


 

Lees enkele properties van MercatorUi.Globals:

Zoom
MercatorWebService40.MercatorWebServiceSoapClient client = new MercatorWebService40.MercatorWebServiceSoapClient();
MercatorWebService40.SecurityInfo si = new MercatorWebService40.SecurityInfo();
si.SecureKey = ... ;

MessageBox.Show("SqlServer = " + client.GlobalsSqlServer(si));

MessageBox.Show("RepData = " + client.GlobalsRepData(si));

MercatorWebService40.StringMws s = client.GlobalsParams(si, "LANGUE_DEF");
if (!string.IsNullOrEmpty(s.LastError))
    MessageBox.Show("GlobalsParams : " + s.LastError);
else
    MessageBox.Show("LANGUE_DEF = " + s.Value);