a·gen·tic a·gil·i·ty

Creating a custom proxy class

TL;DR; Learn how to build a custom proxy class in .NET 3.0 for duplex communication, enabling maintainable code and easy updates when service interfaces change.

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

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:

 1Namespace TeamFoundation.Proxies
 2
 3    Public Class TeamServersClient
 4        Inherits System.ServiceModel.DuplexClientBase(Of Services.Contracts.ITeamServers)
 5        Implements RDdotNet.Proxies.IClientProxy
 6        Implements Services.Contracts.ITeamServers
 7
 8        Public Sub New(ByVal callbackInstance As System.ServiceModel.InstanceContext, ByVal binding As System.ServiceModel.Channels.Binding, ByVal remoteAddress As System.ServiceModel.EndpointAddress)
 9            MyBase.New(callbackInstance, binding, remoteAddress)
10        End Sub
11
12        Public Sub AddServer(ByVal TeamServerName As String, ByVal TeamServerUri As String) Implements Services.Contracts.ITeamServers.AddServer
13            MyBase.Channel.AddServer(TeamServerName, TeamServerUri)
14        End Sub
15
16        Public Function GetServers() As String() Implements Services.Contracts.ITeamServers.GetServers
17            Return MyBase.Channel.GetServers
18        End Function
19
20        Public Sub RemoveServer(ByVal TeamServerName As String) Implements Services.Contracts.ITeamServers.RemoveServer
21            MyBase.Channel.RemoveServer(TeamServerName)
22        End Sub
23
24        Public Function ServceUrl() As System.Uri Implements Services.Contracts.ITeamServers.ServceUrl
25            Return MyBase.Channel.ServceUrl()
26        End Function
27
28    End Class
29
30End 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

Smart Classifications

Each classification [Concepts, Categories, & Tags] was assigned using AI-powered semantic analysis and scored across relevance, depth, and alignment. Final decisions? Still human. Always traceable. Hover to see how it applies.

Subscribe

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.​

SuperControl Logo

SuperControl

YearUp.org Logo

YearUp.org

Alignment Healthcare Logo

Alignment Healthcare

ProgramUtvikling Logo

ProgramUtvikling

Freadom Logo

Freadom

Lockheed Martin Logo

Lockheed Martin

Sage Logo

Sage

Brandes Investment Partners L.P. Logo

Brandes Investment Partners L.P.

Teleplan Logo

Teleplan

Graham & Brown Logo

Graham & Brown

Big Data for Humans Logo

Big Data for Humans

Kongsberg Maritime Logo

Kongsberg Maritime

DFDS Logo

DFDS

Illumina Logo

Illumina

Healthgrades Logo

Healthgrades

Milliman Logo

Milliman

Ericson Logo

Ericson

Cognizant Microsoft Business Group (MBG) Logo

Cognizant Microsoft Business Group (MBG)

Ghana Police Service Logo

Ghana Police Service

Washington Department of Enterprise Services Logo

Washington Department of Enterprise Services

Washington Department of Transport Logo

Washington Department of Transport

Nottingham County Council Logo

Nottingham County Council

Department of Work and Pensions (UK) Logo

Department of Work and Pensions (UK)

Royal Air Force Logo

Royal Air Force

Flowmaster (a Mentor Graphics Company) Logo

Flowmaster (a Mentor Graphics Company)

Brandes Investment Partners L.P. Logo

Brandes Investment Partners L.P.

MacDonald Humfrey (Automation) Ltd. Logo

MacDonald Humfrey (Automation) Ltd.

Cognizant Microsoft Business Group (MBG) Logo

Cognizant Microsoft Business Group (MBG)

Xceptor - Process and Data Automation Logo

Xceptor - Process and Data Automation

Milliman Logo

Milliman