Click here to Skip to main content
15,899,634 members
Please Sign up or sign in to vote.
1.60/5 (2 votes)
hi...

I am using webservice to print a document ,this code wroks from visual studio but not works after hosting it in iis..PLz help...

Here is my code:


C#
public void chefOrderPrinting(OrderFromService objOrder)
        {

            try
            {

                DataTable dtOrderDetails = new DataTable();
                dtOrderDetails = objOrder.OrderDetails.ListToDataTable();
                ReportParameter[] arrParams = new ReportParameter[1];

                // string PrinterName;
                //PrinterName = ApplicationSettings.Default.ChefOrderPrint;
                arrParams[0] = new ReportParameter("rpt_TableNo", objOrder.tableName);
                ReportPrintClass objReportPrintClass;
                objReportPrintClass = new ReportPrintClass("DataSetChefWorkForService_Rpt_ChefWorkForService", dtOrderDetails, @"Report\ChefWorkForService.rdlc", arrParams, 8.27, 11.69, 0.5, 0.5, 0.2, 0.2);
                // objReportPrintClass.Print(@"Send To OneNote 2007", 1);
                
                objReportPrintClass.Print(ConfigurationSettings.AppSettings["PrinterName"], 1);
            }
            catch(Exception ex)
            {
            }

        }


 public ReportPrintClass(string _DataSourceName, DataTable _DataSourceValue, string _ReportPath, double pagewidth, double pageheight, double leftmargin, double rightmargin, double topmargin, double bottommargin)
            {
                this.pageWidth = pagewidth;
                this.pageHeight = pageheight;
                this.leftMargin = leftmargin;
                this.rightMargin = rightmargin;
                this.topMargin = topmargin;
                this.bottomMargin = bottommargin;
                LocalReport report = new LocalReport();
                report.ReportPath = _ReportPath;
                report.DataSources.Add(new ReportDataSource(_DataSourceName, _DataSourceValue));
                Export(report);
                m_currentPageIndex = 0;
            }

            public ReportPrintClass(string _DataSourceName, DataTable _DataSourceValue, string _ReportPath, ReportParameter[] arrParams, double pagewidth, double pageheight, double leftmargin, double rightmargin, double topmargin, double bottommargin)
            //{
            //  public ReportPrintClass(string _DataSourceName, List<productdetails> _DataSourceValue, string _ReportPath, ReportParameter[] arrParams, double pagewidth, double pageheight, double leftmargin, double rightmargin, double topmargin, double bottommargin)
            {
                //objCommonClass.ErrorLog("Service :: InsertOrders()", "printing ", "reached upto Report Print Class");
                this.pageWidth = pagewidth;
                this.pageHeight = pageheight;
                this.leftMargin = leftmargin;
                this.rightMargin = rightmargin;
                this.topMargin = topmargin;
                this.bottomMargin = bottommargin;
                LocalReport report = new LocalReport();
                report.ReportPath = _ReportPath;

                report.DataSources.Add(new ReportDataSource(_DataSourceName, _DataSourceValue));
                report.SetParameters(arrParams);
                Export(report);
                m_currentPageIndex = 0;
            }

            // Routine to provide to the report renderer, in order to
            //    save an image for each page of the report.
            private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
            {
               // objCommonClass.ErrorLog("Service :: InsertOrders()", "printing ", "reached upto Report Print create stream ");
                Stream stream = new FileStream(name +
                   "." + fileNameExtension, FileMode.Create);
                m_streams.Add(stream);
                return stream;
            }

            // Export the given report as an EMF (Enhanced Metafile) file.
            private void Export(LocalReport report)
            {
              //  objCommonClass.ErrorLog("Service :: InsertOrders()", "printing ", "reached upto Report Print Export function ");
                string deviceInfo =
                  "<deviceinfo>" +
                  "  <outputformat>EMF</outputformat>" +
                  "  <pagewidth>" + pageWidth + "in</pagewidth>" +
                  "  <pageheight>" + pageHeight + "in</pageheight>" +
                  "  <margintop>" + topMargin + "in</margintop>" +
                  "  <marginleft>" + leftMargin + "in</marginleft>" +
                  "  <marginright>" + rightMargin + "in</marginright>" +
                  "  <marginbottom>" + bottomMargin + "in</marginbottom>" +
                  "</deviceinfo>";
                Warning[] warnings;
                m_streams = new List<stream>();
                try
                {
                    report.Render("Image", deviceInfo, CreateStream, out warnings);
                }
                catch (LocalProcessingException ex)
                {
                }
                foreach (Stream stream in m_streams)
                    stream.Position = 0;
            }

            // Handler for PrintPageEvents
            private void PrintPage(object sender, PrintPageEventArgs ev)
            {
              //  objCommonClass.ErrorLog("Service :: InsertOrders()", "printing ", "reached upto Report Print page  function ");
                Metafile pageImage = new
                   Metafile(m_streams[m_currentPageIndex]);
                ev.Graphics.DrawImage(pageImage, ev.PageBounds);
                m_currentPageIndex++;
                ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
            }

            public void Print(string printerName, Int16 noCopy)
            {
              //  objCommonClass.ErrorLog("Service :: InsertOrders()", "printing ", "reached upto Report Print page  Print Function ");
                if (m_streams == null || m_streams.Count == 0)
                    return;
                PrintDocument printDoc = new PrintDocument();
                printDoc.PrinterSettings.Copies = noCopy;
                printDoc.PrinterSettings.PrinterName = printerName;
                if (!printDoc.PrinterSettings.IsValid)
                {
                    //string msg = String.Format(
                    //   "Can't find printer \"{0}\".", printerName);
                    //MessageBox.Show(msg, "Print Error");
                    //return;
                }
                printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
                try
                {
                    printDoc.Print();
                }
                catch (Exception ex)
                {
                  //  objCommonClass.ErrorLog("Service :: InsertOrders()", "printing ", "reached upto Report Print page  Print Function "+ex.Message+"  " +ex.InnerException);
                }
            }

            public void Dispose()
            {
               // objCommonClass.ErrorLog("Service :: InsertOrders()", "printing ", "reached upto Report Print page  Print Dispose ");
                {
                    foreach (Stream stream in m_streams)
                        stream.Close();
                    m_streams = null;
                }
            }

        }

    }</stream></productdetails>
Posted
Updated 17-Feb-13 23:05pm
v2
Comments
Sandeep Mewara 18-Feb-13 9:45am    
You sure you hosted it correctly?
aravindnass 18-Feb-13 23:35pm    
Can you tell me how to host...(to make sure I done correctly...)
Richard C Bishop 18-Feb-13 14:52pm    
"not works" is not enough information to describe a problem you are having. Error message? Debugging results?

Deploying a Web Application or Web Service is same. Following will help:
IIS Specific:
1. In IIS7: Deploying ASP.NET Websites on IIS 7.0 [^]
2. In IIS6: Deployment of a Website on IIS[^]
 
Share this answer
 
Try these:

1. Enable and set ASP.Net Impersonation in Authentication section of your site to a custom account.
2. Change identity of application pool, your site is using to a custom account.
3. Change Anonymous Authentication in Authentication section of your site to a custom account.
 
Share this answer
 
Given the amount of information given, my best guess is that it either

a) Can't create the file because of rights issues on the web server
or
b) Can't create the file because the destination directory doesn't exist

It would be easier to answer if you had posted at least SOME information about the errors you encounter...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900