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:


http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpbinding_members.aspx

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

http://kennyw.com/indigo/143

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

Other Related Items:

From promises to prime time: early adopters got into the Web-services game a while ago, but most insurers took a wait-and-see stance and held off for proof ... An article from: Risk & InsuranceThis digital document is an article from Risk & Insurance, published by Thomson Gale on April 15, 2006. The length of the article is 1538 words. The p... Read More >
Iron Python in ActionIron Python in Action

In 2005, Microsoft quietly announced an initiative to bring dynamic languages to the .NET platform. The starting point for this project was a .NET ... Read More >

Software Composition: 7th International Symposium, SC 2008, Budapest, Hungary, March 29-30, 2008. Proceedings (Lecture Notes in Computer Science / Programming and Software Engineering)Software Composition: 7th International Symposium, SC 2008, Budapest, Hungary, March 29-30, 2008. Proceedings (Lecture Notes in Computer Science / Programming and Software Engineering)

This book constitutes the thoroughly refereed proceedings of the 7th International Symposium on Software Composition, SC 2008, held in Budapest, Hu... Read More >

Related Post

Comments are closed.

DotNetNuke Sponsor

 

Most Valuable Blogger
Sponsor