tech·nic·al·ly agile

Creating a custom proxy class

Learn to create a custom proxy class in .NET 3.0 for better maintainability and less code. Enhance your service-oriented architecture skills today!

Published on
1 minute read
Image
https://nkdagility.com/resources/S4XG-Is-FHq

Instead of using the proxy generation features of Visual Studio you can create a custom proxy in .NET 3.0 to handle all of your needs in a more maintainable manor and with less code. This method works best when you have access to the interfaces that created the service.

Here is an example:

Namespace TeamFoundation.Proxies

    Public Class TeamServersClient
        Inherits System.ServiceModel.DuplexClientBase(Of Services.Contracts.ITeamServers)
        Implements RDdotNet.Proxies.IClientProxy
        Implements Services.Contracts.ITeamServers

        Public Sub New(ByVal callbackInstance As System.ServiceModel.InstanceContext, ByVal binding As System.ServiceModel.Channels.Binding, ByVal remoteAddress As System.ServiceModel.EndpointAddress)
            MyBase.New(callbackInstance, binding, remoteAddress)
        End Sub

        Public Sub AddServer(ByVal TeamServerName As String, ByVal TeamServerUri As String) Implements Services.Contracts.ITeamServers.AddServer
            MyBase.Channel.AddServer(TeamServerName, TeamServerUri)
        End Sub

        Public Function GetServers() As String() Implements Services.Contracts.ITeamServers.GetServers
            Return MyBase.Channel.GetServers
        End Function

        Public Sub RemoveServer(ByVal TeamServerName As String) Implements Services.Contracts.ITeamServers.RemoveServer
            MyBase.Channel.RemoveServer(TeamServerName)
        End Sub

        Public Function ServceUrl() As System.Uri Implements Services.Contracts.ITeamServers.ServceUrl
            Return MyBase.Channel.ServceUrl()
        End Function

    End Class

End Namespace

Because your classes implements the service’s interface when that interface changes you will be notified in Visual Studio that this has happened. This is a boon during development as changes can happen often.

This particular class is a duplex proxy, so communication can go both ways. You can download the source code for this from here  .

Technorati Tags: .NET    SOA 

Software Development
Comments

Related blog posts

No related videos found.

Connect with Martin Hinshelwood

If you've made it this far, it's worth connecting with our principal consultant and coach, Martin Hinshelwood, for a 30-minute 'ask me anything' call.

Our Happy Clients​

We partner with businesses across diverse industries, including finance, insurance, healthcare, pharmaceuticals, technology, engineering, transportation, hospitality, entertainment, legal, government, and military sectors.​

Illumina Logo

NIT A/S

ProgramUtvikling Logo
Freadom Logo
Healthgrades Logo
Teleplan Logo
Epic Games Logo
MacDonald Humfrey (Automation) Ltd. Logo
Bistech Logo
DFDS Logo
Xceptor - Process and Data Automation Logo
Lockheed Martin Logo
Trayport Logo
ALS Life Sciences Logo
Jack Links Logo
Sage Logo
Genus Breeding Ltd Logo
Hubtel Ghana Logo
Nottingham County Council Logo
New Hampshire Supreme Court Logo
Washington Department of Transport Logo
Royal Air Force Logo
Department of Work and Pensions (UK) Logo
Ghana Police Service Logo
Slicedbread Logo
Alignment Healthcare Logo
Healthgrades Logo
Sage Logo
Philips Logo
Graham & Brown Logo