Get products via webservice

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 年 前
Hello,
I'm trying to implement a method in webservice pligin (versión nop 2.6) in order to return a product by ID.
The code is:

        public Core.Domain.Catalog.Product GetProductById(int productId, string usernameOrEmail, string userPassword)
            {
                CheckAccess(usernameOrEmail, userPassword);
                if (!_permissionSettings.Authorize(StandardPermissionProvider.ManageOrders))
                    throw new ApplicationException("Not allowed to manage orders");
                
            Core.Domain.Catalog.Product art = _GTproductService.GetProductById(productId);

             return art;


            }

(I previously addedd the method in INopService interfaz)

But I get an error: System.Net.WebExceptionStatus.ReceiveFailure  

I think the problem is related to serialization of object Product:
If I try a webservice returns only the Name of product (returning Type String or object) they Works fine, but when return the object, they fails.

On the other hand, I have revised the properties in yhe Product object generated by the proxy client, and they not have same properties, for example ProductVariants list.

Someone can help me, please?

Thanks
11 年 前
I have the same problem. Did you find any solution?
11 年 前
I think you have to make a serializable DTO class & put your product info in that and return that.  At least that works for me.
11 年 前
Thank you very much.
11 年 前
Can you please be more prcise?
I created A class like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Nop.Core.Domain.Catalog
{
    public class ProductDto
    {
        public virtual string Name { get; set; }

        // Instance members must be virtual on data table objects like Affiliate.cs
        // Virtual is required by data access frameworks so that these frameworks
        // can implement more complex features like lazy loading.

        public virtual string ProductGID { get; set; }

        /// <summary>
        /// Gets or sets the short description
        /// </summary>

        public virtual string ShortDescription { get; set; }

        /// <summary>
        /// Gets or sets the full description
        /// </summary>

        public virtual string FullDescription { get; set; }

        /// <summary>
        /// Gets or sets the admin comment
        /// </summary>

        public virtual string AdminComment { get; set; }

        /// <summary>
        /// Gets or sets a value of used product template identifier
        /// </summary>

        public virtual int ProductTemplateId { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether to show the product on home page
        /// </summary>

        public virtual bool ShowOnHomePage { get; set; }

        /// <summary>
        /// Gets or sets the meta keywords
        /// </summary>

        public virtual string MetaKeywords { get; set; }

        /// <summary>
        /// Gets or sets the meta description
        /// </summary>

        public virtual string MetaDescription { get; set; }

        /// <summary>
        /// Gets or sets the meta title
        /// </summary>

        public virtual string MetaTitle { get; set; }

        /// <summary>
        /// Gets or sets the search-engine name
        /// </summary>

        public virtual string SeName { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the product allows customer reviews
        /// </summary>

        public virtual bool AllowCustomerReviews { get; set; }

        /// <summary>
        /// Gets or sets the rating sum (approved reviews)
        /// </summary>

        public virtual int ApprovedRatingSum { get; set; }

        /// <summary>
        /// Gets or sets the rating sum (not approved reviews)
        /// </summary>

        public virtual int NotApprovedRatingSum { get; set; }

        /// <summary>
        /// Gets or sets the total rating votes (approved reviews)
        /// </summary>

        public virtual int ApprovedTotalReviews { get; set; }

        /// <summary>
        /// Gets or sets the total rating votes (not approved reviews)
        /// </summary>

        public virtual int NotApprovedTotalReviews { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the entity is published
        /// </summary>

        public virtual bool Published { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the entity has been deleted
        /// </summary>

        public virtual bool Deleted { get; set; }

        /// <summary>
        /// Gets or sets the date and time of product creation
        /// </summary>

        public virtual DateTime CreatedOnUtc { get; set; }

        /// <summary>
        /// Gets or sets the date and time of product update
        /// </summary>

        public virtual DateTime UpdatedOnUtc { get; set; }
    }
}


and inside NopService.cs I created a method like this

public List<ProductDto> GetProductCollection(string usernameOrEmail, string userPassword)
        {
            CheckAccess(usernameOrEmail, userPassword);
            if (!_permissionSettings.Authorize(StandardPermissionProvider.ManageCatalog))
                throw new ApplicationException("Not allowed to manage Catalog");

                    
            var productslist = new List<Product>();
            productslist.AddRange(_productService.GetAllProducts(false));
            List<Product> products = productslist;
            List<ProductDto> productsDtos = Mapper.Map<List<Product>, List<ProductDto>>(products);

            
            
            return productsDtos;
            
          
        }


BUT IT DOES NOT WORK :(  what am I missing?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.