views:

8

answers:

0

I need to fax adobe pdf documents from an application running under WCF (c# 4.0). It works, except that it first opens up the pdf document in Adobe Reader when I test it. Obviously this will not work in a server environment! Here is my sample code:

public class InteropFaxMachineComponent : IFaxMachineComponent,
                                          IDisposable
{
    private readonly string machine;
    private IFaxServer faxServer;

    private ILogger logger = NullLogger.Instance;

    public InteropFaxMachineComponent()
        : this(String.Empty) // localhost
    {
    }

    public InteropFaxMachineComponent(string machine)
    {
        this.machine = machine;
        faxServer = new FaxServer();
    }

    public ILogger Logger
    {
        get { return logger; }
        set { logger = value; }
    }

    #region IDisposable Members

    /// <summary>
    /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
    /// </summary>
    /// <filterpriority>2</filterpriority>
    public void Dispose()
    {
        faxServer = null;
    }

    #endregion

    #region IFaxMachineComponent Members

    public void Send(Stream stream, string recipient)
    {
        faxServer.Connect(machine);

        try
        {
            var tempFile = Path.GetTempFileName();
            File.Delete(tempFile);
            tempFile += ".pdf";

            using (var fs = File.Create(tempFile))
                stream.CopyTo(fs);

            try
            {
                var document = (FaxDoc) faxServer.CreateDocument(tempFile);

                document.RecipientName = recipient;
                document.FaxNumber = recipient;

                var result = document.Send();

                if (Logger.IsInfoEnabled)
                {
                    Logger.Info("Queued fax to {0} with fax job #{1}", recipient, result);
                }
            }
            finally
            {
                File.Delete(tempFile);
            }
        }
        finally
        {
            faxServer.Disconnect();
        }
    }

    #endregion
}

Is there some property on FaxServer / FaxDoc that I need to set? Or is this a configuration issue?