C#-Beispiel für Webdienst-API
Dieses Thema enthält Beispielmethoden für die Webdienst-API in C# (C-Sharp). Der Zweck dieses Themas ist, erfahrenen C#-Entwicklern zu helfen, die Verwendung der GFI FaxMaker-Webdienst-API in .NET-Anwendungen zu verstehen. Beispiele könnten umfangreiche Änderungen erfordern, um sie in benutzerdefinierten Anwendungen zu integrieren.
Server- und Benutzerdetails festlegen
// 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 };
Senden eines Faxes
// 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);
Überwachen des Faxsendefortschritts
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); }
Herunterladen von empfangenen Faxen
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); }
C#-Beispiel herunterladen: GFI_WSAPI.zip