Created
July 12, 2012 21:36
-
-
Save markdstafford/3101195 to your computer and use it in GitHub Desktop.
Sample service operation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Data.Services; | |
using System.Data.Services.Common; | |
using System.Linq; | |
using System.ServiceModel; | |
using System.ServiceModel.Web; | |
namespace Scratch.Web | |
{ | |
[ServiceBehavior(IncludeExceptionDetailInFaults = true)] | |
public class ScratchService : DataService<ScratchContext> | |
{ | |
public static void InitializeService(DataServiceConfiguration config) | |
{ | |
config.SetEntitySetAccessRule("*", EntitySetRights.All); | |
config.SetServiceOperationAccessRule("*", ServiceOperationRights.AllRead); | |
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3; | |
config.UseVerboseErrors = true; | |
} | |
[WebGet] | |
public SchedulingResult TestService( | |
string testParam1, | |
string testParam2) | |
{ | |
// NOTE: I never use the params, they're just there for this example. | |
SchedulingResult result = SchedulingResult.Empty; | |
result.Status = OperationStatus.Success.ToString(); | |
result.ResponseID = Guid.NewGuid(); | |
result.AffectedIDs = new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7 }); | |
result.FailedIDs = new List<int>(); | |
result.RecordsAffected = 10; | |
return result; | |
} | |
} | |
public enum OperationStatus | |
{ | |
Success | |
} | |
public class ScratchContext { } | |
public class SchedulingResult// : ServiceInvocationResponse | |
{ | |
public string Status { get; set; } | |
public Guid ResponseID { get; set; } | |
public int RecordsAffected { get; set; } | |
public List<int> AffectedIDs { get; set; } | |
public List<int> FailedIDs { get; set; } | |
public static SchedulingResult Empty | |
{ | |
get { return new SchedulingResult(); } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment