如何使用WCF服务,而DataContract和DataMember?(How to use WCF

2019-10-22 17:36发布

我工作的一个Web应用程序和使用序列化对象JSON.Net 。现在,我想一些WCF服务,该应用程序将在任何平台,例如Android的使用增加。

现在,当我发送一个简单的Ajax请求的Web服务,这是进入无限循环和镀铬控制台日志net::ERR_CONNECTION_RESET ,但是当我添加DataContract到模型中,这个问题得到解决,但在其他形式在整个应用, JSON.Net不序列对象。

这里是我的代码:

[ServiceContract]
public interface IProductService
{
    [OperationContract]
    [WebInvoke(
        Method = "GET",
        ResponseFormat = WebMessageFormat.Json,
        UriTemplate = "product/grid/special?start={start}&size={size}&orderBy={orderBy}&orderByType={orderByType}&productListId={productListId}")]
    PagedResult<Product> specialGrid(int start, int size, string orderBy, string orderByType, int productListId);
}

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ProductService : IProductService
{
    IProductRepository productRepository;

    public PagedResult<Product> specialGrid(int start, int size, string orderBy, string orderByType, int productListId)
    {
        //return start + " " + size + " " + orderBy + " " + orderByType + " " + productListId;
        productRepository = new ProductRepository();
        SearchOption s = new SearchOption(start, size, orderBy, orderByType);
        return productRepository.getSpecialSaleProducts(s, productListId);
    }
}

[Table("Product")]
[DataContract]
public class Product : BaseEntity
{
    public string title { get; set; }
}
文章来源: How to use WCF services without DataContract and DataMember?