C# Web Service API sample
This topic contains sample Web Services API methods in C# (C-Sharp). The scope of this topic is to help experienced C# developers understand how to use the GFI FaxMaker Web Services API in .NET applications. Samples may require extensive modifications to integrate within custom applications.
Set server and user details
// Set the IP of the GFI FaxMaker serverThe machine where GFI FaxMaker is installed.. 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 URLThe Uniform Resource Locator is the address of a web page on the world wide web.. // If an SSLSecure Sockets Layer 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 };
Sending a 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);
Monitoring submitted fax progress
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); }
Downloading received faxes
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); }
Download C# sample: GFI_WSAPI.zip