问题
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