none
总是提示 “远程服务器返回了错误: NotFound。” , Why??? RRS feed

  • 问题

  • 总是提示  “远程服务器返回了错误: NotFound。”  , Why???

    一个PDF到处方法,导出时总是发生错误。可以从http://silverlightpdf.codeplex.com/获得。

    下载的Demo中是没有问题的,但是引用到我的项目中就会出现问题。

               

    #region  PDF导出
            private void PDFToPrint(Grid chart)
            {
                SaveFileDialog fsd = new SaveFileDialog();
                fsd.Filter = "PDF (*.pdf)|*.pdf|*PNG (*.png)|*.png";

                if (fsd.ShowDialog() == true)
                {

                    //Create WriteableBitmap object which is what is being exported.
                    WriteableBitmap wBitmap = new WriteableBitmap(chart, null);
                    int hgt = wBitmap.PixelHeight;
                    int wdth = wBitmap.PixelWidth;

                    //Create EditableImage oblect and iterrate through WriteableBitmap pixels to set EditableImage pixels
                    EditableImage ei = new EditableImage(wdth, hgt);

                    for (int y = 0; y < hgt; y++)
                    {
                        for (int x = 0; x < wdth; x++)
                        {
                            int pixel = wBitmap.Pixels[((y * wdth) + x)];
                            ei.SetPixel(x, y, (byte)((pixel >> 16) & 0xff), (byte)((pixel >> 8) & 0xff), (byte)(pixel & 0xff), (byte)((pixel >> 24) & 0xff));
                        }
                    }

                    //Get the stream from the encoder and create byte array from it
                    System.IO.Stream pngStream = ei.GetStream();

                    printBuffer = new Byte[pngStream.Length];
                    pngStream.Read(printBuffer, 0, printBuffer.Length);

                    switch (fsd.FilterIndex)
                    {
                        case 1:
                            HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(new Uri(Application.Current.Host.Source.ToString().Substring(0, Application.Current.Host.Source.ToString().LastIndexOf("/")) + "/Png2Pdf.ashx"));
                            hwr.Method = "POST";

                            printStream = fsd.OpenFile();
                            printSyncContext = System.Threading.SynchronizationContext.Current;
                            hwr.BeginGetRequestStream(new AsyncCallback(PrintStart), hwr);

                            break;
                        case 2:
                            //Save the PNG to local disk
                            System.IO.Stream fs = fsd.OpenFile();
                            fs.Write(printBuffer, 0, printBuffer.Length);
                            fs.Close();
                            MessageBox.Show("You PNG has been created.", "Export Complete", MessageBoxButton.OK);
                            break;
                    }

                }

            }

            private void PrintStart(IAsyncResult asynchronousResult)
            {
                HttpWebRequest hwr = (HttpWebRequest)asynchronousResult.AsyncState;
                System.IO.Stream stream = (System.IO.Stream)hwr.EndGetRequestStream(asynchronousResult);

                stream.Write(printBuffer, 0, printBuffer.Length);
                stream.Close();

                hwr.BeginGetResponse(new AsyncCallback(PrintGetResponse), hwr);
            }

            private void PrintGetResponse(IAsyncResult asynchronousResult)
            {
                HttpWebRequest hwr = (HttpWebRequest)asynchronousResult.AsyncState;
    WebResponse resp = hwr.EndGetResponse(asynchronousResult);

    问题:

    这里发生了错误,“远程服务器返回了错误: NotFound。”。    这是什么错误???为什么会发生???


                System.IO.Stream respStream = resp.GetResponseStream();
                Byte[] respBytes = new Byte[respStream.Length];

                respStream.Read(respBytes, 0, respBytes.Length);

                printSyncContext.Post(PrintMergeThreads, new HttpWebRequestData(hwr, respBytes));
            }

            private void PrintMergeThreads(object state)
            {
                HttpWebRequestData hwrd = (HttpWebRequestData)state;

                printStream.Write(hwrd.Data, 0, hwrd.Data.Length);
                printStream.Close();
                printStream = null;
                printSyncContext = null;

                MessageBox.Show("Your PDF has been created.", "Export Complete", MessageBoxButton.OK);
            }
            #endregion


    Science and technology is my lover.

    • 已移动 Min Zhu 2012年9月7日 9:17 (发件人:Windows Presentation Foundation)
    2012年8月11日 1:11

全部回复