【发布时间】:2023-03-05 11:11:01
【问题描述】:
我从 asp.net 4 ashx 获取字符串的简单方法有问题。我正在从这个 asp.net 应用程序托管的 silverlight 应用程序中运行以下方法。
private void LoadPlugins()
{
var serviceAddress = _baseAddress
+ "PluginsService.ashx?"
+ DateTime.Now.Ticks;
var client = new WebClient();
client.DownloadStringCompleted += client_DownloadStringCompleted;
client.DownloadStringAsync(new Uri(serviceAddress));
}
void client_DownloadStringCompleted(
object sender,
DownloadStringCompletedEventArgs e)
{
var plugins = e.Result.Split(
new string[] { Environment.NewLine },
StringSplitOptions.RemoveEmptyEntries);
foreach (var plugin in plugins)
{
AddXap(_baseAddress + plugin);
}
}
PluginsService.ashx.cs:
namespace MefPlugins.Web
{
/// <summary>
/// Summary description for PluginsService
/// </summary>
public class PluginsService : IHttpHandler
{
private const string PluginsFolderName = "Plugins/";
public void ProcessRequest(HttpContext context)
{
//var pluginFolder = new DirectoryInfo(
// HttpContext.Current.Server.MapPath(
// PluginsFolderName));
//var response = new StringBuilder();
//if (pluginFolder.Exists)
//{
// foreach (var xap in pluginFolder.GetFiles("*.xap"))
// {
// response.AppendLine(
// PluginsFolderName + xap.Name);
// }
//}
var response = new StringBuilder();
response.Append("test");
context.Response.ContentType = "text/plain";
context.Response.Write(response);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
我收到一个错误:
System.Reflection.TargetInvocationException 未被用户代码处理 Message=操作过程中发生异常,导致结果无效。检查 InnerException 以获取异常详细信息。 堆栈跟踪: w System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() w System.Net.DownloadStringCompletedEventArgs.get_Result() w MefPlugins.MainPage.client_DownloadStringCompleted(对象发送者,DownloadStringCompletedEventArgs e) w System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e) w System.Net.WebClient.DownloadStringOperationCompleted(对象 arg) 内部异常:System.Net.WebException Message=WebClient 请求期间发生异常。 内部异常:System.NotSupportedException Message=无法识别 URI 前缀。 堆栈跟踪: w System.Net.WebRequest.Create(Uri requestUri) w System.Net.WebClient.GetWebRequest(Uri 地址) w System.Net.WebClient.DownloadStringAsync(Uri 地址,对象 userToken) 内部异常:
哪里可能有错误?这是来自http://www.galasoft.ch/sl4u/code/chapter20/20.02-Mef/MefPlugins.zip的示例
【问题讨论】:
-
你知道我会问这个... URI 前缀是什么?
_baseAddress长什么样子? -
当你在它的时候。 “检查 InnerException 以获取异常详细信息”中的内容(如果有的话)
-
serviceAddress 是 "file:////PluginsService.ashx?634485607882333736"
-
{System.Net.WebException:WebClient 请求期间发生异常。 ---> System.NotSupportedException:无法识别 URI 前缀。 w System.Net.WebRequest.Create(Uri requestUri) w System.Net.WebClient.GetWebRequest(Uri address) w System.Net.WebClient.DownloadStringAsync(Uri address, Object userToken) --- Koniec śladu stosu wyjątków wewnętrznych --- }
标签: c# web-services ihttphandler