w0051977
w0051977

Reputation: 15817

Accessing web services uniformly

I have three web services, which were developed by three different vendors and have different URLs; input parameters and output parameters. They are all ASMX web services. They are used to delete records from third party relational databases e.g. I supply a personID and a person is deleted from one system and everything linked to the person. In another system I supply an order ID and everything linked to the order is deleted.

I have several options:

  1. Create a single wrapper class, which is responsible for accessing the web services; supplying common input parameters and accepting common output parameters. This class would have lots of responsibilities.
  2. Create three wrapper classes i.e. one for each web service
  3. Modify the proxies generated by Visual Studio

Which way is best?

Upvotes: 2

Views: 93

Answers (1)

Steven Doggart
Steven Doggart

Reputation: 43743

I would recommend allowing Visual Studio to automatically generate the appropriate proxy classes. I would then implement a wrapper class for each web service so that all of the wrapper classes could implement the same interface. For instance, you may make a common interface that looks like this:

Public Interface IPersonBusiness
    Sub DeletePerson(personId As String)
End Interface

Then, lets say you had two web services. The first, we'll call it WebService1, has a Delete method which takes a person ID followed by the deletion time. The second web service, we'll call it WebService2, has a DeletePeople method which takes an array of person ID's. We could wrap both of these web services using the above common interface, like this:

Public Class WebService1Wrapper
    Implements IPersonBusiness

    Public Sub New(proxy As WebService1)
        _proxy = proxy
    End Sub

    Private _proxy As WebService1

    Public Sub DeletePerson(personId As String) Implements IPersonBusiness.DeletePerson
        _proxy.Delete(personId, Date.Now)
    End Sub
End Class

Public Class WebService2Wrapper
    Implements IPersonBusiness

    Public Sub New(proxy As WebService2)
        _proxy = proxy
    End Sub

    Private _proxy As WebService2

    Public Sub DeletePerson(personId As String) Implements IPersonBusiness.DeletePerson
        _proxy.DeletePeople({personId})
    End Sub
End Classs

I would avoid writing your own proxy code unless you really need to. For instance, if you needed to dynamically call any web service based on some external settings which tell you the method name and parameters to pass, or something like that, then it would be worth looking into.

I would also avoid putting all of the logic to call any of the web services into a single wrapper class. Doing so will make the code unnecessarily ugly and confusing, especially if you need to add additional web services in the future.

Upvotes: 1

Related Questions