Programmatically Controlling Windows Fax Services Using VB.net - Connecting to the Fax Server (Page 4 of 4 )
As a test the first thing we will do is make sure we can connect to the fax server. This is very simple and can be achieved with just a few lines of code. Put a button on your form, and in the click event of the button type the following code. Each part is discussed underneath:
Dim objFaxServer As New FAXCOMEXLib.FaxServer
Dim objFaxOutgoingQueue As FAXCOMEXLib.FaxOutgoingQueue
Try
'Connect to the fax server.
objFaxServer.Connect("srv-fax1")
'Create the outgoing queue
objFaxOutgoingQueue = objFaxServer.Folders.OutgoingQueue
'Ensure that the queue is not blocked or paused
objFaxOutgoingQueue.Blocked = False
objFaxOutgoingQueue.Paused = False
'Set the number of retries
objFaxOutgoingQueue.Retries = 3
'Set the retry delay no of minutes
objFaxOutgoingQueue.RetryDelay = 1
'save the prefs
objFaxOutgoingQueue.Save()
Msgbox("Fax Settings Saved")
Catch ex As Exception
Msgbox("Fax Error" & vbnewline & ex.message)
Exit Function
End Try
The first two lines of code are variables that hold the connections to the server, and the outgoing queue properties. Both types live in the FAXCOMEXLib, as does everything else we use when talking to and configuring the server.
We enclose the whole block of code in a Try Catch block, so we can handle any exceptions gracefully. The first line within the Try is connecting to the fax server, using the objFaxServer variable's Connect method. You just need to give it the name or the IP address of the server. Here it is hard coded but in the real world you would probably put the server name in a config file, or look it up directly.
Once we have a connection, we can start to set the outgoing queue options. The next section of code sets our objFaxOutgoingQueue variable to be the current Outgoing queue of the server (basically, the variable now contains the current settings on the outgoing queue). Then we make sure the outgoing queue is ready to send out jobs by telling it not to be blocked, or paused. Then, we set the number of retries for the job (in this case three) and how long in minutes to wait before each retry (in this case one).
We then call the Save method of the queue variable to write out new settings down to the server. If you don't call the Save method, none of the setting we have specified will change so it's very important to remember to do this. The rest of the code just pops up a message box, and closes the Try/Catch.
If all has gone well, at this point when you run the code you should be given a message box telling you the new settings have been saved. However, if an error has occurred somewhere you will get a message saying 'Fax Error' along with a description of the error.
As this code is not doing much apart from really testing connectivity between you and the service, the error is probably going to be something involving the name of the server being wrong (in the objFaxServer.Connect("srv-fax1") line), or possibly a security issue. The error message normally gives you a good indication of what has happened.
If all has gone well, you are now ready to start sending jobs to the server and getting its current load and jobs. This is covered in part two of the article, so stay tuned!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |