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

starryyujianshu 2012-08-11 09:11:03
一个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
...全文
233 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
starrycheng 2012-08-15
  • 打赏
  • 举报
回复
补齐。。。
starrycheng 2012-08-11
  • 打赏
  • 举报
回复
“远程服务器返回了错误: NotFound。” ,这是什么错误类型,怎样引发的???

8,737

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧