How to Create a Simple Proxy in C#

How to create a simple proxy in C#?

You can build one with the HttpListener class to listen for incoming requests and the HttpWebRequest class to relay the requests.

How to make a simple dynamic proxy in C#

I should have written this sooner, but never mind.

My issue had a special "gotcha" I needed to be able to proxy classes and not interfaces.

There are two solutions to this:

  1. RealProxy and friends, basically means using .NET Remoting. Requires one to inherit from ContextBoundObject.

    • This approach takes advantage of "magic" provided by the .NET JIT compiler
      (which is hardcoded to specifically recognize RealProxy) to let you "override" non-virtual members.
  2. Building a proxy using System.Reflection.Emit as done by spring you can also look at the code of their ProxyFactoryObject. Here are another three articles on the subject.

    • This approach has the crucial disadvantage of limiting you to overriding only virtual members.

How can I make a VERY simple web proxy using ASP.NET?

I guess if all you want to do is read the contents of a request you could use a WebRequest & WebResponse

here are some details on using that

http://www.west-wind.com/presentations/dotnetWebRequest/dotnetWebRequest.htm



Related Topics



Leave a reply



Submit