总是提示 :“远程服务器返回了错误: 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
...全文
302 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
starrycheng 2012-08-15
  • 打赏
  • 举报
回复
补齐。。。
starrycheng 2012-08-11
  • 打赏
  • 举报
回复
“远程服务器返回了错误: NotFound。” ,这是什么错误类型,怎样引发的???
【重要提示】本资源设置为0积分下载,若非0积分请勿轻易下载 亲爱的CSDN用户: 首先感谢你点进这个资源页面。我需要提前说明一个重要情况: 本资源原本已设置为“0积分下载”,即作者希望完全免费共享。但CSDN平台有时会根据文件的下载热度、文件大小、用户权限等因素,自动将部分资源的积分调整为非0数值(如1积分、2积分、5积分等)。这是平台系统的自动行为,而非作者本人的设定。 因此,如果你当前看到该资源的下载所需积分不是0(例如显示为1、2、3……),请谨慎决定是否下载。 如果你按照非0积分支付并下载后发现资源内容不符合预期、链接失效,或者实际上该资源本应是免费的,作者无法为此承担积分损失或退还操作。强烈建议:仅在页面显示为0积分时进行下载。 另外,本资源描述中并未直接提供具体的下载地址或外部链接,因为它本身是一个通过CSDN官方上传通道提交的文件/内容包。如果你看到描述中没有外部网盘地址,这是正常的——资源文件应通过CSDN内置的“下载”按钮获取。若因平台积分显示异常导致你支付了积分,请优先联系CSDN客服咨询积分退还政策,作者没有权限修改平台自动设定的积分值。 感谢你的理解与支持。技术分享本应开放,但受限于平台规则,特此提醒如上。祝学习进步!

8,757

社区成员

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

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