Solved

How to print from a Web Service

Posted on 2010-09-01
4
634 Views
Last Modified: 2012-05-10
Hello Experts,

I have a web service created in VB.Net that is used by a handheld to instantiate and call methods so that the server is doing all the major processing and not the whimpy ARM processor on the handheld.

Anyways, when all the data crunching/ capturing is complete I want to be able to automatically print out the results to a nearby printer. I do this with a seperate class contained in the Web Service. It uses a .rdlc with no report viewer.. simply sends straight to the printer.

Debugging the Web Service locally works like a charm, but when I publish to the server hosting IIS and call the same print method it comes back with Success, but never any print out.
Also, there are no errors ever returned. I still believe this is some kind of permission issue, not an issue with the code.

Here is a list of the things I have done to try getting this to work:
1) Run the Web Service in an application pool with the identity of network user SQLAdmin
2) Logged into the server as SQLAdmin and installed the printer and set it as default
3) Made sure that SQLAdmin is part of the IIS Worker process group
4) Tried using Impersonation in the Web.config for SQLAdmin
5) Tried a registry hack from Microsoft - changing HKEY_CURRENT_USER to HKEY_USERS\.Default
6) Modified .Net framework on the server for Full Trust
7) Set IIS to allow Scripts/Executables (btw.. this is internal to our organization, not open to the public, or else I would tighten security)

Any further ideas would be most helpful.
Also, I didnt post any code due to the size of this original post.
If you feel that it might be a coding issue, just holler and I'll post the Print class

Thanks much,
James
0
Comment
Question by:ASA_MIS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 22

Expert Comment

by:cookre
ID: 33587982
Anything of interest in any of the event logs?
0
 

Author Comment

by:ASA_MIS
ID: 33588054
No sorry, nothing in the event logs as to the problem.

My searching has led to this by Willy Denoyette [MVP]:

You can't use the printer classes from a service (a webservice runs in the context of a windows service) Printer devices are bound to the context of an interactive user, their attributes are strored in the profile (user hive) of the current user (see HKCU).
A web service runs in the context of a non interactive user (ASPNET by default), so there is no specific user profile loaded for webservices or any other service for that matter (aspnet has no user profile).

If printing is required from a service (but you shouldn't), you have to send the request to another service (or better a COM+ server application - see System.EnterpriseServices) This service as to create a logon session for a user by calling LogonUser() (Win32 API) followed by a call to LoadUserProfile() (Win32 API) and ImpersonateLoggedOnUser() (Win32 API) before printing. Note that calling LogonUser is not required if the appliaction is a COM+ application that runs with the credentials of an existing interactive user.

I also see posts from others saying it can work if you use Impersonation.
I've been messing around with that as I have no clue how to write a MFC and dont want to be writing COM+ either. Still can't get it to work. Getting close to Plan B, which is not nearly as sexy.

Thanks,
James
0
 

Author Comment

by:ASA_MIS
ID: 33591247
OK.. Im getting a little closer as I was able to find an error to at least try to troubleshoot.

Here is the Inner Exception:

Microsoft.ReportServices.ReportProcessing.WrapperReportRenderingException: An error occurred during rendering of the report. System.IO.IOException: The process cannot access the file 'c:\windows\SerialNumber_1.emf' because it is being used by another process.

Note: SerialNumber.rdlc is the name of my report

I suspect it's being copied to a temp file and then cant access it?
0
 

Accepted Solution

by:
ASA_MIS earned 0 total points
ID: 33597159
OK for anyone out there wondering if this has been solved it has.

The problem was actually in the code to CreateStream as it was using a FileStream object and for whatever reason was not able to read it back saying it was being used by another process.

So my solution was to use a MemoryStream instead of a FileStream and now it works like a charm.

FYI, I did not have to resort to using Impersonation in the Web.config file, setting up the Application Pool with a custom user was all that was needed.

Hope this helps someone in the future.
James
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question