Muestra de API de servicios web en C#
Este tema contiene métodos de API de servicios web de muestra en C# (C-Sharp). El objetivo de este tema es ayudar a los desarrolles experimentados de C# a comprender cómo utilizar la API de servicios web de GFI FaxMaker en aplicaciones .NET. Las muestras pueden requerir modificaciones significativas para integrarse en las aplicaciones personalizadas.
Establecer detalles de usuario y servidor
// Set the IP of the GFI FaxMaker server. const string IP = "10.44.3.4"; // Set the GFI FaxMaker web service port. By default, this is 8555. const string PORT = "8555"; // Set the GFI FaxMaker WSAPI URL. // If an SSL certificate is configured use https:// rather than http:// const string ENDPOINT = "http://" + IP + ":" + PORT + "/faxmaker/wsapi"; // The Web Service API user's e-mail address as configured in GFI FaxMaker. // User must be registered as a Web Service API user. const string USER_EMAIL = "wsapi_user@testorg.local"; // Active Directory users: Specify the user's Active Directory password. // Non-Active Directory: Password generated by GFI FaxMaker in the user configuration. const string USER_PASSWORD = "abcdefghijklmnopqrstuvwxyz"; // Set the GFI FaxMaker Web Services client proxy var wsFM = new FaxMakerWS.FMSendReceiveClient("FAXmakerWebAPI", ENDPOINT); // Set user var fmUser = new FaxMakerWS.FMUser() { Email = USER_EMAIL, Password = USER_PASSWORD };
Envío de un fax
// Populate the sender details
var sender = new FaxMakerWS.UserDetails()
{
FirstName = "Sender Name", //sender first name
LastName = "Sender Last Name", //sender last name
Email = USER_EMAIL
};
// Set the fax recipient
var recipient = new FaxMakerWS.UserDetails()
{
FirstName = "Recipient Name", //recipient first name
LastName = "Recipient Last Name", //recipient last name
Company = "Company", //recipient company
Department = "Department", //recipient department
Email = "email@address.com", //recipient email address
FaxNumber = "+123456789" //recipient fax number
};
// Add recipient(s) to array.
var recipients = new FaxMakerWS.UserDetails[] { recipient };
// Prepare fax message
var message = new FaxMakerWS.MessageDetails()
{
Subject = "fax subject", //the fax subject
// Specify file containing the fax message body
MessageBodyFile = new FaxMakerWS.FileData()
{
Filename = "msg.txt",
Data = File.ReadAllBytes("msg.txt")
},
Priority = FaxMakerWS.FaxPriority.Normal, //set priority
Resolution = FaxMakerWS.FaxResolution.Normal, //set resolution
UseFaxLine = FaxMakerWS.FaxLineType.None //send over a specified fax line.
};
// Send the fax
FaxMakerWS.FaxJobID[] faxJobIds;
var result = wsFM.SendFax(out faxJobIds, fmUser, sender, recipients, message);
Console.WriteLine("SendFax() Result: " + result);
Supervisión de progreso de fax enviado
FaxMakerWS.FaxSendingStatus faxStatus;
FaxMakerWS.FMResult StatusUpdatesResult;
// run loop for each jobID (i.e. recipient)
foreach (var jobID in faxJobIds)
{
// Poll for status updates until fax is successfully sent or failed
do
{
StatusUpdatesResult = wsFM.GetSendingFaxStatusUpdates
(out faxStatus, fmUser, jobID.FaxUID);
if (StatusUpdatesResult == FaxMakerWS.FMResult.Success)
{
Console.WriteLine("Status: FaxID = " + jobID.FaxUID + " -> " +
faxStatus.Status);
// Pause for 30 seconds before checking again for status.
Thread.Sleep(30000);
}
else
{
Console.WriteLine("Call to monitor fax with ID " + jobID.FaxUID +
" failed, result " + result);
}
}
while (
StatusUpdatesResult == FMResult.Success &&
faxStatus.Status != SendingStatus.Sent &&
faxStatus.Status != SendingStatus.Failed);
}
Descarga de faxes recibidos
FaxMakerWS.ReceivedFaxDetails faxDetails;
FaxMakerWS.FileData faxImage;
var result = wsFM.GetNextFax(out faxDetails, out faxImage, fmUser);
if (result == FaxMakerWS.FMResult.Success)
{
// if there is a fax in the queue...
if (faxDetails != null)
{
// ... print the details of the fax
Console.WriteLine("Fax ID: " + faxDetails.FaxUID);
Console.WriteLine("Date Received: " + faxDetails.WhenReceived);
Console.WriteLine("Number of Pages: " + faxDetails.NosPages);
//Save fax image data to disk
File.WriteAllBytes(faxImage.Filename, faxImage.Data);
}
else
{
// when there are no faxes in the queue...
Console.WriteLine("The queue for " + USER_EMAIL + " is empty.");
}
}
else
{
Console.WriteLine("getNextFax Failed, result: " + result);
}
Descargar muestra #C: GFI_WSAPI.zip