【发布时间】:2010-07-25 19:15:39
【问题描述】:
我正在通过 http 调用 REST 服务,该服务返回一个流作为响应。 我的客户端代码如下所示:
Uri uri = new Uri(remoteAddress);
var webRequest = (HttpWebRequest)WebRequest.Create(uri);
webRequest.Method = "GET";
webRequest.ContentType = "multipart/mixed";
webRequest.BeginGetResponse(responseResult =>
{
HttpWebResponse response = (HttpWebResponse)webRequest.EndGetResponse(responseResult);
this.messages = ParseResponse(response);
Complete(false);
}, null);
我在这一行收到以下错误:
HttpWebResponse response = (HttpWebResponse)webRequest.EndGetResponse(responseResult);
System.Net.ProtocolViolationException 未被用户代码处理 由于对象的当前状态,消息=操作无效。 堆栈跟踪: 在 System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod,对象状态) 在 System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在 LaharSubProxy.SubscribeAsyncResult`1.c__DisplayClass1.b__0(IAsyncResult responseResult) 在 System.Net.Browser.BrowserHttpWebRequest.c__DisplayClassd.b__b(Object state2) 在 System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(对象状态) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态,布尔 ignoreSyncCtx) 在 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 在 System.Threading.ThreadPoolWorkQueue.Dispatch() 在 System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() 内部异常:
这让我非常抓狂,因为异常没有指向任何有用的东西。我在 fiddler 中启用了“流式传输”选项,但没有看到任何流量/错误。
请帮忙!
【问题讨论】:
标签: .net silverlight wcf silverlight-4.0 httpwebrequest