Remote Proxy Pattern

Well, the time came for the third specialization I’m going to write about the proxy pattern, in this case is the remote proxy pattern.

It’s role is to provide the client the functionality to interact with an object that it might not be in the client machine, this proxy will inherit from the same interface than the remote object, but it wont have it’s own implementation, it will simply call the remote object. In short, it’s like the web services, when we make a web reference the wsdl file will be created, but it won’t be able to perform any concrete action, because the real object, is somewhere else.

The example will be like this, we will pretend to have a remote service, think about a WCF service, or even a web service, and we’re going to make our method calls to invoke the methods on the proxy, in fact, the proxy’s job is to stand between the real object and the client, not only this kind of proxy, but all. So we’re showing something to the client, but he doesn’t know that we’re calling the real object inside our proxy.

Here is the example, it’s by far the easiest and shortest one about this series of examples about the proxy design pattern.

Step 1: Add a service reference to our project, in this case I’m going to use a public web service, so we right-click our project and select ‘Add Service Reference…’ then we paste this url (http://soatest.parasoft.com/calculator.wsdl), and name our service ‘CalculatorService’.
Thanks to the Parasoft crew for publishing the service.

Step 2: We will code our main method

using System;

namespace Structural.Proxy.Remote
{
    class Program
    {
        static void Main(string[] args)
        {
            CalculatorService.ICalculator calculator = new CalculatorService.CalculatorClient();

            Console.WriteLine(calculator.add(7.3f,6.2f));

            Console.ReadKey();
        }
    }
}

It’s important to mention that we’re coding against a proxy, then the proxy will call the real service operation.

Hope it helps.

Best regards,
Esteban.

About these ads

About Esteban
Ssr .NET software architect from Buenos Aires, Argentina, who has been having fun with Microsoft technologies since 2002. I’ve worked for many companies and projects. I really enjoy challenges, as much as I enjoy my work. And no, I don't update my blog very often.

One Response to Remote Proxy Pattern

  1. Pingback: Proxy Pattern « A blog by Esteban Murchio

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: