Search code examples
c#asp.netweb-servicesvisual-studio-2010crystal-reports

Error when printing in server with web service


My web service uses C# to print an invoice from the server printer. This service works fine when called in debug mode, but after sending it to the IIS location and running the project from web explorer, I get this error:

No printers are installed.

System.Drawing.Printing.PrinterSettings.GetHdevmodeInternal(String printer) at System.Drawing.Printing.PrinterSettings.GetHdevmodeInternal() at System.Drawing.Printing.PrinterSettings.GetHdevmode(PageSettings pageSettings) at CrystalDecisions.CrystalReports.Engine.PrintOptions.CopyTo(PrinterSettings printer, PageSettings page)

What is the problem? The same machine will function properly in debug mode, but not in live.

This section of code throws the exception:

reportClass.PrintOptions.PrinterName = clsDeclaration.defultPrinter1;
reportClass.PrintToPrinter(numberOfCopies, true, 1, 1);

Solution

  • I got the solution

    The reason it works while on the development machine is that the development web service is running in the context of your windows login, which probably has the correct printers set up. On the server, it’s probably running as the Network Service or as the Local System account.

    The solution is to setup printers for the system account using the instructions below. You will also need to change the identity of the application pool that your app is using to use the LocalSystem identity.

    enter image description here