C # SOAP API Client / Wrapper Design

Background
I am interacting with a SOAP webservice using C #. I am working in Visual Studio and have successfully set up a service reference and can use the web service in my code.

My questions are related to "how best" for creating a client / wrapper in an API given the powerful capabilities of C # as a language.

Central class "Request"
I had to create a general class to handle requests to a service and thus handle all the various permutations of specific API errors (there are many) and degrade gracefully. This class can also be a "Controller" for an API client, which also provides a common interface between internal calls and the outside world / code.

Then I noticed the huge variety of data types that each API request requires and can return. Surely this means that this "request" functionality cannot be handled in general (and must be implemented in every specific type of request - for example, authentication, vehicle position, jobs / orders)?

Or, if possible, how can C # as a language help me in working with types abstractly?

As always, thanks for your reading time and any tips you might save yourself.

+3


source to share


1 answer


The question is a bit vague in its details, but I'll try to offer some tips.

At first I think it is wise for you to create a wrapper on top of the external API. I'll use an example of an external email provider to try and answer your question.

Imagine we have a third party email API and we want to create a wrapper around it.

I would start by creating a wrapper that behaves the way I expect the email API to work. There should be methods like:


public EmailResponse SendEmail(EmailRequest request) { }
public User GetUser(string email) { }
public void OptOut(string email) { }

      



I start by designing what the client thinks is both domain-wide and easy to use.

Then you create an implementation of the wrapper interface, which directly converts to the third party API. The example above might require two external API calls to send the email, but the person using your wrapper won't know this.

In my opinion, wrappers are useless if you tie them too closely to a specific implementation.

There are many language features in C # that make this approach possible, but I think just using a simple interface would suit your needs. You don't have to make it harder than it is.

+2


source







All Articles