MSDN

Setting A Web Proxy Through Configuration In .NET Applications

Specially in enterprise environments, proxy servers are used to access the Internet.

In a Windows / Internet Explorer environments there is a proxy server configuration in Internet Properties > Connections > LAN settings > Proxy server.

Although these configurations are tightly connected to Internet Explorer, any well behaved Windows application should, at least, allow the user to choose to use them.

In applications targeting the .NET framework, these the proxy server can be set on a per call basis. Several networking classes have a Proxy property that receives a value implementing the IWebProxy interface.

In order for the Windows/ Internet Explorer configuration to be used, the application must be configured to use the default proxy settings.

This configuration is done in the machine or application file in the proxy element of the defaultProxy configuration section in the system.net section group:

<configuration>
  <system.net>
    <defaultProxy enabled="true">
      <proxy usesystemdefault="True"/>
    </defaultProxy>
  </system.net>
</configuration>

You can use this configuration also to set a specific proxy to be used by your application. In the following example, a proxy setting for using the Fiddler Tool is used:

<configuration>
  <system.net>
    <defaultProxy enabled="true">
      <proxy proxyaddress="http://ipv4.fiddler"/>
      <proxy proxyaddress="http://127.0.0.1:8888"/>
    </defaultProxy>
  </system.net>
</configuration>

Unfortunately, this is a MachineToApplication setting and, for that reason, is not allowed in the user settings configuration file, when in a shared installation. In these type of installations, the default Windows / Internet Explorer settings should be used as a default. If a user needs or wants to specify proxy server settings, application specific proxy server settings must be used but, assigning the user defined proxy server configuration to the GlobalProxySelection.Select property will allow its use for the entire application.

Updated: Corrected proxy address when using Fiddler following Eric Lawrence’s comment:

> <proxy proxyaddress="http://ipv4.fiddler/" />

That line should not work. Fiddler doesn't register anything in DNS, so for "ipv4.fiddler" to have any meaning, Fiddler must already be being used as the proxy.

The proper setting for Fiddler use should be:

<proxy proxyaddress="http://127.0.0.1:8888" />

Another Great Example Of Silverlight Deep Zoom – From ViaTecla Innovation Laboratories

VTPostal2008


This innovative use of Deep Zoom uses screenshots of sites powered by ViaTecla’s software solutions to form a picture of a Santa Claus.

Saved By The .NET Framework Cleanup Tool – Again!

I don’t know what’s wrong with my XP system (besides the fact that I’m still using it) but I couldn’t install .NET 3.5 without removing .NET 2.0 and now I couldn’t install apply SP1 without removing .NET 3.0 and 3.5.

Fortunately, I was rescued by Aaron Stebner’s .NET Framework cleanup Tool – both times.

Kudos Aaron!

How To Issue Server Callbacks

Callbacks were introduced in ASP.NET 2.0 and is a simple mechanism for calling page or control functionality without page rendering and without the user noticing a post back.

For a page or control to handle callbacks, all it needs is to implement the ICallbackEventHandler Interface.

When the client calls back to de page or control, the initial state of the controls is posted along with the control being called upon in the __CALLBACKID field and the callback parameter in the __CALLBACKPARAM field.

It’s quite a simple procedure.

But what if you want to issue a callback server side?

In order for a request to be identified as a callback (IsCallback), the request must be a postback (IsPostback) and the before mentioned fields must be in the post data of the request. On the other hand, for a request to be considered a postback, the level of server calls (Transfer or Execute) must be 0 (meaning that the current request hasn’t made any Transfer or Execute calls) or the type of the page is the same of the Handler for the current request and the HTTP method is POST.

Changing the HTTP method is (as far as I know) impossible. So, if the request is not already a POST, there’s no way to issue a callback.

Setting the post data is easier. All it’s needed is to override the page’s DeterminePostBackMode method (or in a page adapter) and return the post data previously saved in a context item. Something like this:

protected override NameValueCollection DeterminePostBackMode()
{
    NameValueCollection postBackMode = Context.Items["callbackPostData"] as NameValueCollection;

    return (postBackMode != null) ? postBackMode : base.DeterminePostBackMode();
}

And issue a callback is something like this:

IHttpHandler handler = this.Context.Handler;
try
{
    NameValueCollection postData = new NameValueCollection();
    postData.Add("__CALLBACKID", sender);
    postData.Add("__CALLBACKPARAM", this.argument.Text);

    Context.Items["callbackPostData"] = postData;

    Page calledPage = (Page)PageParser.GetCompiledPageInstance("~/Callback1.aspx", this.Server.MapPath("~/Callback1.aspx"), this.Context);

    this.Context.Handler = calledPage;

    StringWriter writer = new StringWriter();

    Server.Execute(calledPage, writer, false);

    this.response.Text = writer.ToString();
}
finally
{
    this.Context.Handler = handler;
}

You can find an implementation of a caller and a called page here.

Improving Debugging And Testing Through Assertions

Reading through the The Typemock Insider blog, I came across this post from Gil Zilberfeld.

I myself tend to fall in Gil’s practice ("binary search" debugging), but I don’t think Kent Beck has the right solution.

Gil’s suggestion of using Isolator is tempting (I don’t miss an opportunity to use it), but still not my favorite one.

I prefer to use debug assertions. Debug assertions can be used when running a debug version of the application to pop-up assertion messages and when running unit tests to fail tests.

In order to use debug assertions in unit tests a “special” trace listener is needed to make the test fail when its Fail method is called.

public class UnitTestTraceListener : global::System.Diagnostics.DefaultTraceListener
{
     public UnitTestTraceListener() : base()
    {
        this.Name = "UnitTest";
        this.AssertUiEnabled = false;
    }

    public override void Fail(string message, string detailMessage)
    {
        Microsoft.VisualStudio.TestTools.UnitTesting.Assert.Fail("Debug.Assert Failed: " + message + " " + detailMessage);
    }
}

Now, all you need to do is register it.

Registering the trace listener can either be done in code:

System.Diagnostics.Trace.Listeners.Remove("Default");
System.Diagnostics.Trace.Listeners.Add(new UnitTestTraceListener());

or configuration:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <assert assertuienabled="false"/>
    <trace>
      <listeners>
        <clear/>
        <add name="UnitTest" type="UnitTestTraceListener"/>
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

And if I’m using Isolator I have the take in account the accesses made in the call to the Assert method. More fun to me.

The Future Of C#


If you were able to attend this session at PDC or Tech-Ed EMEA Developers, you were presented with a first class presentation of the future of C#, presented, respectively, by Anders Hejlsberg and Mads Torgersen.


For the near future (.NET 4.0) C# will have:




  • Dynamically Typed Objects


  • Optional and Named Parameters


  • Improved COM Interoperability


  • Co- and Contra-variance

A preview of the compiler as a service was shown, but that’s not for the .NET 4.0 / Visual Studio 2010 timeframe. Probably, not even for the next.


Starting with .NET 4.0, C# and Visual Basic will converge in terms of features and follow a path of co-evolution going into the future.


No! That doesn’t mean that XML literals will be in C# in a foreseeable future. What that means is that the above list also applies to Visual Basic.


Talking of Visual Basic evolution, the _ line continuation character has been retired. If you have any use for the underscore, please visit http://www.unemployedunderscores.com/.


Resources:


PDC And Tech-Ed Wrap-Up

(It might seem a bit late for this, but, lately, I’ve been having a lot on my mind. So here it goes.)

This was my first PDC. It was just as I had been told.

For those who don’t know, the PDC is all about the future. The near future (.NET 4.0 and Windows 7) and the further future (Windows Azure, “Oslo”, “Dublin”, “Geneva”).

Next year’s PDC (Yes! Apparently, there’ll be one next year) will be also held in Los Angeles from November 17 to 20, and (I suspect) will be the commercial launch of the Azure Services Platform and a better story to tell about “Oslo”.

Tech-ED EMEA Developers, on the other hand, is more about the present and the near future. But, this year, attendees were able to have a sneak peek at what had bee shown at the PDC.

Next year’s Tech-ED EMEA Developers will be held in Berlin from November 2 to 6. Probably, like in 2006, it will be the launch of .NET 4.0 and Visual Studio 2010.

And I intend to attend both.

MSDN Ramp Up Program

MSDN Ramp Up Program

I just came across this: www.MyRampUp

Ramp Up is a free, online, community-based program that can help users save time in learning Microsoft technology.

The easy-to-access content (provided by subject-matter gurus) is specifically tailored to the Ramp Up program, and offered in a variety of forms (whitepaper, v-lab, codecast and slidecast).

Program Guide

The currently available routes are:

SharePoint for Developers track - learn more

Visual Studio 2008 track - learn more

Aspiring Developer - learn more

Success with Java and C# - learn more

Next Level Visual Basic - learn more

Next Level Microsoft.NET - learn more

Currently, there are no assessments in the program, so it's quicker than ever to graduate and receive the reward (25% off on certification and 50% off on e-Learning - only for graduates of Ramp Up).

PDC2008 Is Over! PDC2009 Is Coming!

PDC2008: Is My House On The Cloud Or Is The Cloud In My House?

This year’s PDC is mostly about the cloud.


Everyone is talking about the cloud: cloud services, cloud computing, etc. but I’m not sure everyone has the same understanding of what the cloud is. Let’s say it’s a cloudy concept.


So, what is this cloud thing, anyway?


Let’s take Windows Home Server (WHS) as an example. Microsoft provides a set of services through homeserver.com that allows me to control my home server and access my other PCs in the home network. I guess I could say that homeserver.com is a cloud platform that puts my house in the cloud.


On the other hand, WHS is built on top of Windows Server 2003 which allows me to take full advantage of its web server (IIS) to expose services through homeserver.com. Services that could be for my personal use or that I could provide to others, thus putting my house on the cloud.


At a larger scale, that’s how I see the cloud and it’s usage. An indistinct universe of service providers and service consumers where some are just providers, others are just consumers and others are both (service aggregators, value added brokers, etc.)


I guess that Microsoft’s view in regards to the cloud and WHS is aligned with mine because there will be two PDC sessions about this:





  • Tue 10/28 | 5:15 PM-6:30 PM | 409A

    Presenter(s): CJ Saretto, Fabian Uhse

    Learn how to build applications and services deployed on Windows Home Server that power PCs and devices throughout a connected home. See an example home automation and energy management service, and watch the creation of an on-premises service that exposes HVAC, window shades, and lighting controls to all devices on the home network. Hear how to package the service as a Windows Home Server add-in, quickly create a configuration UI, deploy a PC application for controlling the service, and demonstrate control from other devices such as TVs and cell phones.




  • Wed 10/29 | 10:30 AM-11:45 AM | 409A

    Presenter(s): Brendan Grant, CJ Saretto

    Learn how to leverage the Remote Access platform in Windows Home Server to expose on-premises services running in the connected home to the Internet. See how to expose a home automation service running on Windows Home Server to the Internet, and watch a demonstration that shows how to expose services that may be hosted on other devices inside the connected home using Windows Home Server as a gateway. Finally, see a sneak preview of Home Server and Live Mesh working together to further enhance the remote experience for the connected home.


Windows Home Server Resources

And, suddenly, a cloud in your future is not a ad thing, quite the opposite.