通常我看到 WCF REST JSON 的代码很可能是:
// Start the service and browse to <a href="http://:/SampleService/help[ServiceContract] public">http://<machine_name>:<port>/SampleService/help [ServiceContract]
public interface ISampleService {
[WebGet(UriTemplate = "")]
List<SampleItem> GetCollection();
这意味着引入了接口。但在某些情况下,我在代码中看到的接口根本没有使用过。如
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class AlertService
{
AlertContext alertProxy = new AlertContext();
AlertDetailsContext alertDetailProxy = new AlertDetailsContext();
Analytics analyticsProxy = new Analytics();
[OperationContract]
[WebInvoke(BodyStyle=WebMessageBodyStyle.Bare, RequestFormat=WebMessageFormat.Json, ResponseFormat=WebMessageFormat.Json, UriTemplate="/SearchAlerts")]
public List<Alert> SearchAlerts(AlertFilter filter)
{
WebOperationContext.Current.OutgoingResponse.Headers.Add("Cache-Control", "no-cache, must-revalidate");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Expires", "Sat, 26 Jul 1997 05:00:00 GMT");
这里直接使用类,为什么呢?