我在使用 WCF Rest 模板作为基础制作的服务中实现了一些方法。
这些方法工作正常并且正在返回 Json 数据。
但是,我实现了一种返回对象列表的方法,该方法似乎不断地给我一个“此网页不可用”错误。我不知道如何调试这个问题或者可能是什么原因。有人有建议吗?
[WebGet(UriTemplate = "GetCars/{TypeId}", RequestFormat=WebMessageFormat.Json)]
public List<Car> GetCars(String TypeId)
{
CarFilter carFilter = new CarFilter();
carFilter.requestType = "product";
carFilter.numberOfCars = -1;// Convert.ToInt32(numberOfCars);
carFilter.carIdTo = -1;//Convert.ToInt32(carIdTo);
carFilter.carIdFrom = -1;//Convert.ToInt32(carIdFrom);
return CarDataAccess.GetCar(Convert.ToInt32(TypeId), carFilter);
}
谢谢。
最佳答案
有两件事需要检查。首先,通过添加 [ServiceKnownType] 属性来查看这是否是 KnownType 问题:
[ServiceKnownType]
此外,在 .NET 4.0 之前的版本中,如果这是 WCF,您仍然需要方法上的 OperationContract
属性。试试这个:
[OperationContract]
[WebGet(UriTemplate = "GetCars/{TypeId}", RequestFormat=WebMessageFormat.Json)]
public List<Car> GetCars(String TypeId)
关于c# - WCF 休息方法 - 该网页不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13715646/