[IronPython] Silverlight and Catching HttpWebRequest Errors

Jimmy Schementi Jimmy.Schementi at microsoft.com
Thu Jun 26 06:27:32 CEST 2008


Thanks Dino. I'll bug the Networking guys about this.

> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Dino Viehland
> Sent: Wednesday, June 25, 2008 9:23 PM
> To: Discussion of IronPython
> Subject: Re: [IronPython] Silverlight and Catching HttpWebRequest
> Errors
>
> While it might look like those events are public they aren't really.
> BrowserHttpWebRequest is an internal type so its members are not
> directly exposed - even if those members are public.  If it were
> overriding some methods on a base class or interface that were public
> we could then access them.  It does implement an interface which has
> those members, INetworkProgress, but that interface is also internal!
> So even though there are public methods there is no publicly accessible
> way for us to get to those events :(.  If the interface was public we'd
> be able to access them.
>
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Jimmy Schementi
> Sent: Wednesday, June 25, 2008 9:09 PM
> To: Discussion of IronPython
> Subject: Re: [IronPython] Silverlight and Catching HttpWebRequest
> Errors
>
> So, did some homework on this. Taking a look at BrowserHttpWebRequest
> with Reflector, it definitely has a public ProgressFailed event, but it
> says it's read-only.
>
> Dino/Curt, could this behavior happen because BrowserHttpWebRequest has
> a methods and events by exactly the same name?
>
>     private EventHandler<NetworkProgressChangedEventArgs>
> ProgressChanged;
>     private EventHandler<NetworkProgressChangedEventArgs>
> ProgressCompleted;
>     private EventHandler<NetworkProgressChangedEventArgs>
> ProgressFailed;
>
>     // Events
>     public event EventHandler<NetworkProgressChangedEventArgs>
> ProgressChanged;
>     public event EventHandler<NetworkProgressChangedEventArgs>
> ProgressCompleted;
>     public event EventHandler<NetworkProgressChangedEventArgs>
> ProgressFailed;
>
> Michael, regardless, for simple downloading I'd use WebClient; the code
> is much more concise:
>
> from System.Net import WebClient
> from System import Uri
>
> def Downloaded(sender, args):
>     print args.Result
>
> uri = Uri('http://localhost:2060/index.html')
> req = WebClient()
> req.DownloadStringCompleted += Downloaded
> req.DownloadStringAsync(uri)
>
> Do you still have time to change your book's example? =P
>
> ~Jimmy
>
> > -----Original Message-----
> > From: users-bounces at lists.ironpython.com [mailto:users-
> > bounces at lists.ironpython.com] On Behalf Of Michael Foord
> > Sent: Wednesday, May 14, 2008 2:58 PM
> > To: Discussion of IronPython
> > Subject: Re: [IronPython] Silverlight and Catching HttpWebRequest
> > Errors
> >
> > Michael Foord wrote:
> > > Michael Foord wrote:
> > >> On May 12, 9:17 am, Jimmy Schementi
> <Jimmy.Scheme... at microsoft.com>
> > >> wrote:
> > >>
> > >>> The actual type returned by HttpWebRequest.Create() is a
> > >>> BrowserHttpWebRequest, but it's internal (not sure why). Anyway,
> it
> > >>> has a ProgressFailed event you can hook.
> > >>>
> > >>
> > >> Hello Jimmy,
> > >>
> > >> As far as I can tell it *doesn't* have the 'ProgressFailed' event.
> > >>
> > >
> > > The actual failure I see is:
> > >
> > > Exception: [Arg_COMException]
> > > Arguments:
> > > Debugging resource strings are unavailable. Often the key and
> > > arguments provide sufficient information to diagnose the problem.
> See
> > >
> >
> http://go.microsoft.com/fwlink/?linkid=106663&Version=2.0.30226.1&File=
> > mscorlib.dll&Key=Arg_COMException
> > >
> > >
> > >
> >
> > Sorry for the noise. This one is actually for the sake of google (and
> > all who sail in her).
> >
> > Exception
> >    at MS.Internal.XcpImports.GetDownloaderBytes(IntPtr element,
> IntPtr&
> > outBytes, Int32& outSize)
> >    at MS.Internal.InternalWebRequest.GetResponseStream()
> >    at System.Net.BrowserHttpWebRequest.Completed(Object sender,
> > EventArgs e)
> >    at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32
> > typeIndex, Delegate handlerDelegate, Object sender, Object args)
> >    at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr
> > unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
> >
> > Michael
> >
> > > This is using Safari. As I'm developing on the Mac I can't use
> > > debugging, nor can I test in Firefox because of the bug in Chiron.
> > >
> > > It looks like some people have similar errors:
> > >
> > >    http://silverlight.net/forums/p/12500/40967.aspx#40967
> > >
> > > and a guy in the comments here:
> > >
> > >
> > > http://www.cameronalbert.com/post/2008/03/HttpWebRequest-Helper-
> for-
> > Silverlight-2.aspx
> > >
> > >
> > > All the best,
> > >
> > > Michael Foord
> > > http://www.ironpythoninaction.com/
> > >
> > >> I need to make cross-domain POST, and although the request gets
> made
> > >> successfully I'm getting a COM Arg Exception everytime (I think
> > >> because the server is slow to respond). This is screwing me at the
> > >> moment.
> > >>
> > >> FYI - when I execute the following code in Silverlight:
> > >>
> > >>   from System.Net import WebRequest
> > >>   from System import Uri
> > >>
> > >>   u = Uri('http://www.v.com')
> > >>   req = WebRequest.Create(u)
> > >>   print req.ProgressFailed
> > >>
> > >> I get the following exception:
> > >>
> > >> Traceback (most recent call last):
> > >>   File "None", line 6, in <undefined>
> > >> AttributeError: 'BrowserHttpWebRequest' object has no attribute
> > >> 'ProgressFailed'
> > >>
> > >> All the best,
> > >>
> > >> Michael Foord
> > >> http://www.ironpythoninaction.com/
> > >>
> > >>
> > >>> PS. If you REALLY want synchronous downloading, just hack on
> > >>> XMLHttpRequest
> > >>>
> > >>> def download(url):
> > >>>     request = HtmlPage.Window.CreateInstance("XMLHttpRequest")
> > >>>     request.Invoke("open", "GET", url, false) # false means
> > synchronous
> > >>>     request.Invoke("send", "")
> > >>>     return request.GetProperty("responseText")
> > >>>
> > >>> :)
> > >>>
> > >>> ~js
> > >>> ________________________________________
> > >>> From: users-boun... at lists.ironpython.com
> > >>> [users-boun... at lists.ironpython.com] On Behalf Of Michael Foord
> > >>> [fuzzy... at voidspace.org.uk]
> > >>> Sent: Monday, May 12, 2008 12:58 AM
> > >>> To: Discussion of IronPython
> > >>> Subject: [IronPython] Silverlight and Catching HttpWebRequest
> > Errors
> > >>>
> > >>> Hello guys,
> > >>>
> > >>> I have a problem with catching network errors raised by
> > HttpWebRequest
> > >>> in Silverlight. (Not necessarily an IronPython specific question
> -
> > but
> > >>> you guys are so intelligent you are always the first place I
> > turn...)
> > >>>
> > >>> HttpWebRequest uses an async model for fetching resources. If
> there
> > >>> is a
> > >>> problem (triggered usually by a slow response from the server),
> > then it
> > >>> can happen *after* I have made the request - but before my
> callback
> > is
> > >>> invoked. This gives me nowhere to catch the exception, as
> > >>> effectively it
> > >>> happens 'inside Silverlight'. I wondered if there was a
> solution...
> > ?
> > >>>
> > >>> def callback(asyncResult):
> > >>>     ...
> > >>>
> > >>> uri = Uri(some_url)
> > >>> req = HttpWebRequest.Create(uri)
> > >>>
> > >>> req.BeginGetResponse(AsyncCallback(callback), object())
> > >>>
> > >>> The error occurs after BeginGetResponse, but before calback. Any
> > ideas
> > >>> for catching it?
> > >>>
> > >>> Michael Foordhttp://www.ironpythoninaction.com/
> > >>>
> > >>> _______________________________________________
> > >>> Users mailing list
> > >>>
> >
> Us... at lists.ironpython.comhttp://lists.ironpython.com/listinfo.cgi/user
> > s-ironpython.com
> > >>>
> > >>> _______________________________________________
> > >>> Users mailing list
> > >>>
> >
> Us... at lists.ironpython.comhttp://lists.ironpython.com/listinfo.cgi/user
> > s-ironpython.com
> > >>>
> > >>>
> > >> _______________________________________________
> > >> Users mailing list
> > >> Users at lists.ironpython.com
> > >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> > >>
> > >
> > > _______________________________________________
> > > Users mailing list
> > > Users at lists.ironpython.com
> > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >
> > _______________________________________________
> > Users mailing list
> > Users at lists.ironpython.com
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com




More information about the Ironpython-users mailing list