Select version
v7.7 v7.6 v7.5 v7.3 v7.1 v7.0 v6.8 v6.7 v6.6 v6 v5 v4 v3 v2

Add a New Web Service

uCommerce uses ServiceStack to open up web services to use for all sort of tasks, e.g adjusting the basket throughout the checkout flow, custom variant handling, anything you need.

You can use this capabililty to surface your own web services and extend the default set of services provided with uCommerce.

Three things comes in play when you want to add a new web service:

  • Implement the specific webservice from ServiceStack interfaces.
  • Implement a single interface from uCommerce with no methods needed IContainsWebservices.
  • Register the new web service interface with uCommerce.

Purpose of IContainsWebservices

The interface is a so-called marker interface, which sole purpose is to let uCommerce know that a given DLLs contains web services, hence the name :)

A marker interface contains requires no methods or properties, so basically no implementation required to use it.

    
    
    namespace UCommerce.Web.Api
    {
    	/// <summary>
    	/// Marker interface for getting assemblies to register within ServiceStack AppHost.
    	/// </summary>
    	public interface IContainsWebservices
    	{
    	}
    }
    
    

The reason for implementing the interface: IContainsWebservices is that ServiceStack on startup asks for a list of assemblies containing webservices for the AppHost.

We use that to our advantage, to make it possible to contribute to that list of assemblies through service stack - hence the inteface IContainsWebservices. When you register a component we will look up the assembly and provide that to ServiceStack, that then will know to scan your assembly with your located web services.

Because of this approach it is important that your actual web services are located within the same assembly as your registered component that implements IContainsWebservices.

Implement and Register IContainsWebservices

Implementing IContainsWebservices: (Once again, remember to have it in the same assembly as your actual web-services.)

    
    
    namespace MyUcommerceApp
    {
    	public class AssemblyTag : IContainsWebservices
    	{
    
    	}
    }
    
    

Create a new Webservices.config file and place it in uCommerce/Apps/MyApp:

    
    <configuration>
    	<components>
    		<component id="MyUcommerceAppWebServices"
    			service="UCommerce.Web.Api.IContainsWebservices, UCommerce.Web.Api"
    			type="MyUcommerceApp.AssemblyTag, MyUCommerceApp"/>
    	</components>
    </configuration>
    

Having trouble to register your component? Please see Register a Custom Component.

Implement the Web Service

Finally you want to implement the actual web service, which is done by inheriting the Service class in the namespace ServiceStack.ServiceInterface.

    
    	public class MyWebService : ServiceStack.ServiceInterface.Service
    	{
    
    	}
    

That's it. You're all done.

Now if you need to learn more details on how to create a web service please read on in the next article "How to create a basket web service".

uCommerce Aps - Studsgade 29B - 8000 Aarhus C - Denmark
Phone +45 61 799 997 - Email info@ucommerce.dk uCommerce logo