getting fax number from FaxOutgoingJob

282 views Asked by At

I'm trying to get a fax number from IFaxOutgoingJob but keep getting COM error.

FaxServer g_objFaxServer = new FaxServer();
IFaxServer fs = (IFaxServer)g_objFaxServer;

//connection logic...

IFaxOutgoingQueue oq = fs.Folders.OutgoingQueue;
FaxOutgoingJobs jobs = oq.GetJobs();

string fx = "13101230000";

FaxOutgoingMessageIterator iter = oa.GetMessages();
iter.MoveFirst();  //iter = oa oa=>outgoingarchive = already sent
while (!iter.AtEOF)
{
     ...
     if (iter.Message.Recipient.FaxNumber == fx)
     {
         System.Console.WriteLine("orig sched time: {0},  #: {1},  fn: {2}", 
                                         iter.Message.OriginalScheduledTime,
                                         iter.Message.Recipient.FaxNumber,
                                         iter.Message.DocumentName);
     }
     iter.MoveNext();
}
foreach (IFaxOutgoingJob j in jobs)  //jobs=outgoingqueue = to be sent
{
    if (j.Recipient.FaxNumber == fx) // <------------possible error?
    {
        System.Console.WriteLine("orig sched time: {0},  #: {1},  fn: {2}", 
                                                  j.OriginalScheduledTime,
                                                  j.Recipient.FaxNumber,
                                                  j.DocumentName);
    }
}

I can't really debug in this environment so can't figure out what's going on. Error seems to happen when it's trying to access j.Recipient.FaxNumber because call trace says there's an error, calling IFaxOutgoingJob.get_Recipient().

Side question is FaxOutgoingJob and IFaxOutgoinJob seems to serve the same purpose. Why would one use IFaxOutgoingJob against the other one? I know i is interface but it doesn't really make sense why there are two if they're doing the same thing.

2

There are 2 answers

0
Mike On

Ok I feel bad about this. I think my code has a flaw.

'jobs' in the second for loop block was the old one that I was reusing and it wasn't being refreshed and that's why it couldn't find it later when some time has passed (in matter of minutes), especially, after a job was sent.

3
Michael Edenfield On

Chances are, at the point when you're trying to read the information, the Recipient property isn't available. I would first recommend checking if j.Recipient == null, though if your getting an error inside get_Recipient that may not help.

The other option is to just wrap the entire block of code in a `try ... catch (COMException ex)' block, and skip the ones where you can't read the recipient. You would need to come back and retry those later somehow.


To answer your question about FaxOutgoingJob vs IFaxOutgoingJob, if you're going to do any kind of COM programming you really need to understand the difference between a class and an interface. But, in a nutshell:

  • An interface, like IFaxOutgoingJob, is just a contract - it's a list of properties and methods that you can use to talk to some other system in a well-defined way. The interface, by itself, doesn't do anything. It merely tell you what you can do if you have an object that exposes that interface.
  • A class, like FaxOutgoingJob, implements an interface when it wants to let other people use it. By doing so, it's making the promise that it can do all the things the interface says are possible. It does the real work of making the interface properties and method actually do something.

In COM, interfaces are special because all interaction between COM clients and COM libraries is through interfaces. C# hides all the gory details from you, but if you want to use a COM object, you have to do it through the interface. But in C#, you can't "just use interfaces" because they're not objects -- you can't create them. So, the C# "import library" has created a class who's sole purpose is to be a "skeleton" that the interface can attach to.

You should never really use the class directly, since the COM interface system won't know what to do with it. The only time you ever really need to use a class like that is when you're creating a new object, you would do something like:

var newFax = new FaxOutgoingJob as IFaxOutgoingJob;

and from them on, use the interface as usual.