Mental Jetsam

By Peter Finch

Accessing a C# Webservice through a proxy

Posted by pcfinch on March 12, 2008

Creating and accessing a Web service from C# (.NET) is really simple, but when running the Web service from your C# application on you location machine, or a web server, you may find the application unable to access a remote Web service. If you are behind a firewall and using a proxy server to access the Internet you may need to tell the Web service to use the default proxy server for your machine.

MSNSearchService s = new MSNSearchService();
s.Proxy = WebProxy.GetDefaultProxy();

5 Responses to “Accessing a C# Webservice through a proxy”

  1. Matthew said

    I’d love to make a contextually sensitive comment, but I’m afraid on this topic there is next to no chance.

    Allow me instead to say – keep up the blogging!

  2. Christoph said

    Thanks for the tipp but where did you get the object WebProxy from?

  3. pcfinch said

    WebProxy is a static in the System.Net namespace. If you have not included the namespace with “using System.Net ;” then you can reference it directly using

    s.Proxy = System.Net.WebProxy.GetDefaultProxy();

  4. pcfinch said

    System.Net.WebProxy.GetDefaultProxy() is deprecated, try the following.

    s.Proxy = System.Net.WebRequest.DefaultWebProxy;

  5. mark baer said

    This method is obsolete now(since .NET 2.0)…Do you know what it is under .NET 4.0?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: