Search code examples
c#web-serviceswcfprintingserver-side

Server side printing from WCF web service


I am stuck for more than a week trying to print from WCF web service on a shared network printer. I did not find any solution anywhere on the web.

So, there is a VM Windows 2016 web server with IIS 10 hosting a WCF web service. That web service should be able to print a document on a shared network printer attached to some other computer in the network. That shared network printer is installed on the web server and it prints fine from any desktop application. But when I call web service method to print something, it won't print.

I tried everything I found on the web. I tried using different accounts for IIS Application pool. When I use any of the built-in accounts (LocalService, LocalSystem, NetworkService, ApplicationPoolIdentity), no printers are listed from the code. When I use local admin account, the service shows installed printers, but I get error: Settings to access printer are not valid. Btw, I am logging to the server with this account and can print normally with the same printer (for example test page or from NotePad).

I also tried Microsoft's registry hack: http://support.microsoft.com/kb/184291/en-us

I tried to impersonate different users and also to avoid impersonation.

I also created a small desktop application for printing and when I start it from command prompt it prints well. But when I start the same process from the service, again previously mentioned problems occur.

I even tried everything in different environment (different computers, but the same configuration) and the service behaves the same.

I will not post web service C# code here, because I am sure that the code is not the problem. The same code prints well on my development machine and also when used in desktop application on the web server. The problem is somewhere in the privileges of the account which web service is using.

Of course, all users are granted to print and to manage printer.

Is it possible to print from web service at all? Maybe I am trying to do something that is not recommended or not possible?


Solution

  • I just wanted to close this question and give the solution that solved the problem.

    After weeks of attempts to make this work, I gave up of trying to make web service call the local printer. Please, don't go there.

    Initial architecture of the system was that a desktop application calls web service for many different functionalities and, among them, for printing documents. But I had to change that and develop a small console application for printing, so this desktop application is not going to a web service to print, but rather calls that small console application with parameters. Not very elegant, but it works.