C# 3.0 in a Nutshell
C# 3.0 in a Nutshell, Third Edition A Desktop Quick Reference By Joseph Albahari, Ben Albahari
September 2007
Pages: 858


Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Webclient Exception In Linqpad, Internet connection attempts go poopy
TCBOOBuckPyland
post Jun 18 2009, 08:53 AM
Post #1


New Member
*

Group: Members
Posts: 3
Joined: 18-June 09
Member No.: 18,708



I'm having some issues with LINQPad making connections to the Internet. I use a web proxy through ISA Server, and LINQPad is configured with the same settings used by IE. Every connection attempt gives the message, "Error: An exception occurred during a WebClient request". I was trying to download the samples for the book, "LINQ in Action" through Samples->Download more samples... when this happenned. Every other feature of LINQPad that connects to the Internet gives the same message.

I would have used the built-in Report Bug, but it fails as well. Other than that, you have a fine product here. tongue.gif
Go to the top of the page
 
+Quote Post
JoeAlbahari
post Jun 18 2009, 04:13 PM
Post #2


Advanced Member
******

Group: Members
Posts: 215
Joined: 15-February 08
From: Perth, Australia
Member No.: 90



Hi there

LINQPad uses the standard WebProxy class, which it populates using the web proxy details that you enter. (Go to Help | Check for Updates, and click Specify Web Proxy).

Here's the code it uses to configure the WebClient object:

CODE
public WebClient GetWebClient ()
{
    System.Net.ServicePointManager.Expect100Continue = !DisableExpect100Continue;
    var wc = new WebClient ();
    if ((Address ?? "").Trim ().Length == 0) return wc;
    string a = Address.Trim ();
    if (Port > 0) a += ":" + Port;
    var proxy = new WebProxy { Address = new Uri (a) };            
    if ((Username ?? "").Trim ().Length > 0)
    {
        if ((Domain ?? "").Trim ().Length > 0)
            proxy.Credentials = new NetworkCredential (Username.Trim (), Password, Domain.Trim ());
        else
            proxy.Credentials = new NetworkCredential (Username.Trim (), Password);
    }
    wc.Proxy = proxy;
    return wc;
}


If you're about to use the WebClient class yourself and I've done anything wrong here, please let me know!

Joe
Go to the top of the page
 
+Quote Post
TCBOOBuckPyland
post Jun 18 2009, 06:10 PM
Post #3


New Member
*

Group: Members
Posts: 3
Joined: 18-June 09
Member No.: 18,708



QUOTE (JoeAlbahari @ Jun 18 2009, 04:13 PM) *
Hi there

LINQPad uses the standard WebProxy class, which it populates using the web proxy details that you enter. (Go to Help | Check for Updates, and click Specify Web Proxy).

Here's the code it uses to configure the WebClient object:

Snipped for brevity by Buck.

If you're about to use the WebClient class yourself and I've done anything wrong here, please let me know!

Joe


Hiya, Joe. Thanks for the code. I'll definitely give this a try. This also jump-started my memory, and a co-worker had a similar issue with using credentials in some VB.NET code for an ASP.NET project. I'll ask him what he did to get his code to work.

Stay tuned...


--Buck
Go to the top of the page
 
+Quote Post
TCBOOBuckPyland
post Jun 22 2009, 12:42 PM
Post #4


New Member
*

Group: Members
Posts: 3
Joined: 18-June 09
Member No.: 18,708



Using your code, I figured out that the Address is supposed to be a proper URI. I left out the "http://" before. Works like a champ, now. Thanks again for the help.
Go to the top of the page
 
+Quote Post
JoeAlbahari
post Jun 24 2009, 03:33 AM
Post #5


Advanced Member
******

Group: Members
Posts: 215
Joined: 15-February 08
From: Perth, Australia
Member No.: 90



Terrific!

Thanks for letting me know.

Joe
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 22nd November 2009 - 05:10 AM