从Web服务打印文档 [英] Print document from web service

查看:88
本文介绍了从Web服务打印文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...



我正在使用webservice来打印文档,此代码从visual studio中删除但在iis..PLz帮助中托管之后无效...



这是我的代码:





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:


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>

推荐答案

部署Web应用程序或Web服务是相同的。以下将有所帮助:

IIS特定:

1.在IIS7中:在IIS 7.0上部署ASP.NET网站 [ ^ ]

2.在IIS6中:在IIS上部署网站 [ ^ ]
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[^]


试试这些:



1.启用并将站点的身份验证部分中的 ASP.Net模拟设置为自定义帐户。

2.更改应用程序池的身份,您的网站用于自定义帐户

3 。将您网站的身份验证部分中的匿名身份验证更改为自定义帐户。
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.


根据给出的信息量,我最好的猜测是它r $>


a)由于网络服务器上的权利问题,无法创建文件



b )无法创建文件,因为目标目录不存在



如果您至少发布了有关错误的一些信息,那么回答会更容易你遇到......
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...


这篇关于从Web服务打印文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆