Silverlight 4中的HttpWebRequest抛ProtocolViolationException [英] Silverlight 4 HttpWebRequest throwing ProtocolViolationException

查看:353
本文介绍了Silverlight 4中的HttpWebRequest抛ProtocolViolationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我调用通过HTTP REST服务返回的流作为响应。 我的客户code看起来像这样:

I'm invoking a REST service via http which returns a stream as the response. My client code looks like so:

                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);

我收到的这条线以下错误:

I'm getting the following error on this line:

 HttpWebResponse response = (HttpWebResponse)webRequest.EndGetResponse(responseResult);

System.Net.ProtocolViolationException是未处理由用户code   消息=操作无效由于对象的当前状态。   堆栈跟踪:        在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(对象状态2)        在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()   的InnerException:

System.Net.ProtocolViolationException was unhandled by user code Message=Operation is not valid due to the current state of the object. StackTrace: at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at LaharSubProxy.SubscribeAsyncResult`1.<>c_DisplayClass1.b_0(IAsyncResult responseResult) at System.Net.Browser.BrowserHttpWebRequest.<>c_DisplayClassd.b_b(Object state2) at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() InnerException:

这是推动我绝对坚果,因为异常没有指向任何有用的东西。我已经启用了小提琴手的流的选项,但我没有看到任何流量/错误。

This is driving me absolutely nuts since the exception is not pointing to anything useful. I have enabled the "streaming" option in fiddler but I'm not seeing any traffic/errors.

请帮忙!

推荐答案

嗯whatdya知道,问题是这一行:

Well whatdya know, the problem is this line:

webRequest.ContentType = "multipart/mixed";

看起来这是一个SL错误/细微的差别。我评论说,线路输出和错误消失! 我还要补充一点,code因为是工作得很好,在一个传统的控制台/ Windows的应用程序。

Seems like this is a SL bug/nuance. I commented that line out and the error disappears! I should also add that the code as is works just fine in a traditional console/windows app.

这个帖子我指出了正确的方向。由于微软!!!!!!

This post pointed me the right direction. Thanks Microsoft!!!!!!

这篇关于Silverlight 4中的HttpWebRequest抛ProtocolViolationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆