How to use WCF services without DataContract and DataMember?

女生的网名这么多〃 提交于 2019-12-24 07:19:03

问题


I'm working on a web application and serializing objects using JSON.Net.now, i want to add some WCF services to this application that will be used in any platform for example android.

now, when i send a simple ajax request to web service, it's go to infinite loop and chrome console logs net::ERR_CONNECTION_RESET, but when i add DataContract to the model, this problems get to solved, but in the other forms in the entire of application, JSON.Net does not serialize objects.

Here is my codes:

[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; }
}

来源:https://stackoverflow.com/questions/29754874/how-to-use-wcf-services-without-datacontract-and-datamember

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!