private static SearchProductsRealtimeResponse RemoteSearchProducts(RemoteSearchProductsRealtimeRequest request)
            {
                var client = new TransactionServiceClient(request.RequestContext);
                PagedResult <ProductSearchResult> searchResults = null;
                long currentChannelId = request.RequestContext.GetPrincipal().ChannelId;

                var retrieveAttributeSchemaEntriesDataRequest = new GetProductMediaAttributeSchemaEntriesDataRequest();

                retrieveAttributeSchemaEntriesDataRequest.QueryResultSettings = new QueryResultSettings(new ColumnSet(new string[] { "ATTRIBUTE", "DATATYPE" }), PagingInfo.CreateWithExactCount(2, 0), new SortingInfo("DATATYPE"));
                var attributeSchemaEntries     = request.RequestContext.Execute <EntityDataServiceResponse <ProductAttributeSchemaEntry> >(retrieveAttributeSchemaEntriesDataRequest).PagedEntityCollection.Results;
                var imageAttributeId           = attributeSchemaEntries.Single(r => r.DataType == AttributeDataType.Image).RecordId;
                var attributesValuesToRetrieve = Convert.ToString(imageAttributeId);

                if (request.CategoryId.HasValue)
                {
                    searchResults = new PagedResult <ProductSearchResult>(client.SearchProductsByCategoryId(currentChannelId, (long)request.CategoryId, request.RequestContext.LanguageId, request.ChannelId, request.CatalogId, attributesValuesToRetrieve, request.QueryResultSettings), request.QueryResultSettings.Paging);
                }
                else if (!string.IsNullOrWhiteSpace(request.SearchText))
                {
                    searchResults = new PagedResult <ProductSearchResult>(client.SearchProductsByText(currentChannelId, request.SearchText, request.ChannelId, request.CatalogId, attributesValuesToRetrieve, request.QueryResultSettings), request.QueryResultSettings.Paging);
                }
                else
                {
                    throw new ArgumentOutOfRangeException("request", "A valid category identfier or search text must be provided to search products.");
                }

                return(new SearchProductsRealtimeResponse(searchResults));
            }
            private static SearchProductsServiceResponse SearchProducts(SearchProductsServiceRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.QueryResultSettings, "request.QueryResultSettings");

                if (request.ChannelId < 0)
                {
                    throw new ArgumentOutOfRangeException("request", request.ChannelId, "Channel identifier cannot be less than zero.");
                }

                if (request.CatalogId < 0)
                {
                    throw new ArgumentOutOfRangeException("request", request.CatalogId, "Catalog identifier cannot be less than zero.");
                }

                long currentChannelId = request.RequestContext.GetPrincipal().ChannelId;

                if (request.ChannelId != currentChannelId && request.CategoryId.HasValue)
                {
                    RemoteSearchProductsRealtimeRequest realtimeRequest  = new RemoteSearchProductsRealtimeRequest(request.ChannelId, request.CatalogId, request.CategoryId.Value, request.QueryResultSettings);
                    SearchProductsRealtimeResponse      realtimeResponse = request.RequestContext.Execute <SearchProductsRealtimeResponse>(realtimeRequest);

                    return(new SearchProductsServiceResponse(realtimeResponse.ProductSearchResults));
                }
                else if (request.ChannelId != currentChannelId && !string.IsNullOrWhiteSpace(request.SearchText))
                {
                    var realtimeRequest = new RemoteSearchProductsRealtimeRequest(request.ChannelId, request.CatalogId, request.SearchText, request.QueryResultSettings);
                    SearchProductsRealtimeResponse realtimeResponse = request.RequestContext.Execute <SearchProductsRealtimeResponse>(realtimeRequest);

                    return(new SearchProductsServiceResponse(realtimeResponse.ProductSearchResults));
                }

                GetProductSearchResultsDataRequest dataRequest = null;

                if (request.ChannelId == currentChannelId && request.CategoryId.HasValue)
                {
                    dataRequest = new GetProductSearchResultsDataRequest(request.ChannelId, request.CatalogId, request.CategoryId.Value, request.QueryResultSettings);
                }
                else if (request.ChannelId == currentChannelId && !string.IsNullOrWhiteSpace(request.SearchText))
                {
                    GetProductBarcodeDataRequest  productBarcodeRequest  = new GetProductBarcodeDataRequest(request.SearchText);
                    GetProductBarcodeDataResponse productBarcodeResponse = request.RequestContext.Execute <GetProductBarcodeDataResponse>(productBarcodeRequest);

                    if (productBarcodeResponse != null && productBarcodeResponse.Barcode != null && !string.IsNullOrWhiteSpace(productBarcodeResponse.Barcode.ItemId))
                    {
                        dataRequest = new GetProductSearchResultsDataRequest(request.ChannelId, request.CatalogId, productBarcodeResponse.Barcode.ItemId, request.QueryResultSettings);
                        dataRequest.UseFuzzySearch = false;
                    }
                    else
                    {
                        dataRequest = new GetProductSearchResultsDataRequest(request.ChannelId, request.CatalogId, request.SearchText, request.QueryResultSettings);
                    }
                }
                else
                {
                    throw new NotSupportedException("A valid category identifier or search text has not been specified. One of these values need to be set correctly.");
                }

                var dataResponse = request.RequestContext.Execute <EntityDataServiceResponse <ProductSearchResult> >(dataRequest);

                return(new SearchProductsServiceResponse(dataResponse.PagedEntityCollection));
            }