Documentation

Ucommerce includes full API reference documentation and lots of helpful articles to help you build your e-commerce site as effortlessly as possible.

Topics Payment Providers
v7.18

Migrating Services to Web Api

Starting with version 8, Servicestack (previously used for creating web services tied together with Ucommerce) is no longer a part of Ucommerce. This means that any custom services created for ServiceStack needs to be migrated to WebAPI when upgrading to this version or higher. Web api is shipped with Ucommerce since 7.11.17348

Comparison of an old and a new service

Previously with Service Stack a webservice could look something like this. The routing could be configured in multiple ways, but basically Service Stack would detect what webservices shipped as long as you also had the IContainsWebServices registration in windsor enabled. That would look something like this:

    
        
    <component id="DemoStoreWebApi" 
    				service="Ucommerce.Web.Api.IContainsWebservices, Ucommerce.Web.Api"
    				type="Ucommerce.RazorStore.Services.AssemblyTag, Ucommerce.RazorStore"/>
    

The interface "UCommerce.Web.Api.IContainsWebservices, UCommerce.Web.Api" and the Assembly "UCommerce.Web.Api" no longer exists so if they are part of IoC somehow, you will get a YSOD. So you need to remove all code and configuration referencing those.

Old service

    
        
    namespace UCommerce.RazorStore.Services.Commands
    {
    	using ServiceStack.ServiceInterface;
    	using ServiceStack.ServiceInterface.ServiceModel;
    	using UCommerce.Api;
    
    	public class AddToBasket
    	{
    		public int? CatalogId { get; set; }
    		public int Quantity { get; set; }
    		public string Sku { get; set; }
    		public string VariantSku { get; set; }
    		public bool AddToExistingLine { get; set; }
    	}
    
    	public class AddToBasketResponse : IHasResponseStatus
    	{
    		public ResponseStatus ResponseStatus { get; set; }
    	}
    
    	public class AddToBasketService : ServiceBase<AddToBasket>
    	{
    		protected override object Run(AddToBasket request)
    		{
    			TransactionLibrary.AddToBasket(request.Quantity, request.Sku, request.VariantSku, addToExistingLine: true, executeBasketPipeline: true);
    			return new AddToBasketResponse();
    		}
    	}
    }
    	
    

New service

    
    
    namespace YourNamespace
    {
    	public class AddToBasket
    	{
    		public int? CatalogId { get; set; }
    		public int Quantity { get; set; }
    		public string Sku { get; set; }
    		public string VariantSku { get; set; }
    		public bool AddToExistingLine { get; set; }
    	}
    
        [RoutePrefix("ucommerceapi/yourApiprefix")]
        public class BasketController : ApiController
        {
            [Route("yourApi/addToBasket")]
            [HttpPost]
            public IHttpActionResult AddToBasket([FromBody] AddToBasketRequest request)
            {
                TransactionLibrary.AddToBasket(request.Quantity, request.Sku, request.VariantSku, addToExistingLine: true, executeBasketPipeline: true);
                return Ok();
            }
    
            ...
        }
    }
    
    

General info

Please note that using 'ucommerceapi' as a routeprefix in your webservices for apps can be a good idea to ensure that all webservices are picked up on all CMSes.

Please note that Web Api web services are automatically registered and loaded so the only important step is to reference the version of Web Api that Ucommerce uses. You can find the dependency Ucommerce uses on the dependencies list in our Ucommerce NuGet package. Take a look at the NuGet package here: https://www.nuget.org/packages/uCommerce/7.19.0.18260