Setting a Web Proxy on a WebService in .NET 3.x

A couple of weeks ago I wrote an article stating that Microsoft had changed how the proxy class for web services gets created. Many people found this helpful, but I got one question on the post that really needs to be answered in a new post:

Thanks, now can you tell us where to set the Proxy settings, .Proxy variable no longer exists, and ClientCredentials is not obvious if this is the replacement?

ClientCredentials is not the replacement. This is a situation where running the debugger and viewing the object model after the object is created is very helpful.

Since many of the properties in the web service are typed as interfaces or abstract classes, many of the properties we actually need won’t be visible during design time. All design time knows about is the types defined in the interface or abstract class. And since making an HTTP connection is only one of several ways we might connect using WCF, it does not make sense to have the proxy property part of that interface.

One of the properties of the web service’s proxy class is “EndPoint” which holds the definition of where our web service will be connecting to. Inside this property is another property, “Binding,” which is defined as System.ServiceModel.Channels.Binding. One of the implementations of System.ServiceModel.Channels.Binding is System.ServiceModel.BasicHttpBinding. The BasicHttpBinding object is where the proxy definitions are defined.

If you just want to use the default web proxy that is defined in the operating system, you just need to make sure that UseDefaultWebProxy is set to true, which it is by default. If you want to set it to a specific address, you’ll want to set the ProxyAddress property to the location of the HTTP proxy, which can also be set in the configuration file for your application.

You can find the full documentation for the BasicHttpBinding class here:

To set the credentials for the proxy, you use ChannelFactory.Credentials. You can find a full description of this (and its limitations) here:

Other places talking about BasicHttpBinding and WCF

  • Https with BasicHTTPBinding – Note to Self- So if you are looking to implement SSL using basicHttpBinding for your WCF service, look no further. Here is your config file settings The modified basicHttpBindinging to allow security mode = Transport <basicHttpBinding> …
  • SOA: Making the Paradigm Shift Part 11 of N- Welcome to the 11th article in the series. In this article, I will take a broad detour from the abstract into the concrete with WCF. The title of this article is “Introduction to WCF: Architecture and the “ABCs” of Indigo. …
  • Setting UserName ClientCredentials in WF SendActivity- I was recently asked if there is a way to set custom UserName credentials in a SendActivity. I did some investigation and couldn’t find any OOB way do achieve this. So the next step was to look into WCF’s awesome extensibility mechanism …
  • Configuring a WCF Binding for https- Both BasicHttpBinding and WSHttpBinding support Transport Security (https). However, neither do it by default. The binding must be configured correctly. Here is how to do it in code: BasicHttpBinding binding = new BasicHttpBinding(); …

Like this Article? Subscribe to get every article sent to your email.

Related Post

  • Silverlight, Web Services and DatasetsSilverlight, Web Services and Datasets I sat down today to learn about using Silverlight and Dataset from a Web Service.  Something you’d think would be rather trivial. I mean, seriously folks.  We use Datasets as a […]
  • WebServices – Error HandlingWebServices – Error Handling Several weeks ago I presented jQuery at the DotNet User’s Group in Connecticut.  As part of that presentation, I mentioned that I handle errors from my WebServices in a slightly […]
  • Mixing ASP.NET, jQuery and JSONMixing ASP.NET, jQuery and JSON I received the following question last week: I am building a web application... I have a form with server control textbox and dropdownlist... how can I send this to the […]
  • Visual Studio 2008 Changes WebService ProxyVisual Studio 2008 Changes WebService Proxy Just a short post today to address a change in how VS 2008 handles proxying your web services. In earlier versions of Visual Studio, when we went to suck in the ASMX files that […]
  • ASP.NET JSON  and ViewStateASP.NET JSON and ViewState I received the following question recently about my article "ASP.NET AJAX using JSON - Here’s how." If we update the value of a textbox or label via a JSON web service call - will the […]

About Dave Bush

Dave Bush is a .NET programmer and Certified ScrumMaster who is passionate about managing risk as it relates to developing software. When he is not writing or speaking about topics related to Application Lifecycle Risk Management (ALRM), he is an example to his peers as he develops web sites in the ASP.NET environment using industry best practices.

Awards & Certs