Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Service wrapper

I am writing a dll that is referencing to some WCF service. The dll is functioning as a Gateway of the service and all calls are going through it. Probably there can be concurrent calls .

I have referenced the service but now I cannot decide how to write the wrapper functions correctly.

Is there some example or best practice for this functionality.

like image 235
Night Walker Avatar asked Apr 30 '12 11:04

Night Walker


People also ask

What does a service wrapper do?

A service wrapper is a computer program that wraps arbitrary programs thus enabling them to be installed and run as Windows Services or Unix daemons, programs that run in the background, rather than under the direct control of a user. They are often automatically started at boot time.

What is wrapper WSDL?

The WSDL document, Web services wrapper, and nicknames. The Web services wrapper uses the operations in a port type that have a SOAP binding with an HTTP transport. The input messages in the operation, and the associated types or elements become columns in the nickname.


1 Answers

I would make wrapper that matches the web service interface. It would also be a good idea to wrap up all of the objects exposed. Basically create a proxy. What I find really useful for this type of thing is to create an interface that matches the API and implement that. That way, you can create a dummy version of the DLL for testing without the overhead (or potential costs) associated with the WCF call. It would also make it much simpler if you need to replace the WCF call with an alternate provider in the future.

As an example, lets assume that we have an WCF service to an external provider for processing a payment. Something like this:

void ProcessPayment(float amount);

We could easily hook this into our code. The problem is that a simple change to the interface would result in us having to make changes everywhere the code is referenced. The same would be necessary if we changed providers to someone else, even if the interface was almost identical. Adding something like a simple interface:

interface IPaymentProvider
{
    void ProcessPayment(float amount);
}

Would completely decouple our code from the WCF service. We could easily build a class like this:

class PaymentProviderAWrapper : IPaymentProvider
{
    void ProcessPayment()
    {
        // Call the WCF service
    }
}

That we could load dynamically with a factory or dependency injection framework like Spring.NET. Changing to a provider B would be as simple as creating a new wrapper:

class PaymentProviderBWrapper : IPaymentProvider
{
    void ProcessPayment()
    {
        // Call provider B's Native DLL
    }
}

Switching your code from provider A to B would be as simple as changing a configuration setting.

Even if we compiled the library directly into our code, all we would need to do is change the construction logic to use the new library. The rest of our application would not change at all. Just a simple recompile.

like image 126
Graymatter Avatar answered Sep 28 '22 12:09

Graymatter