public
Created

Sample service operation

  • Download Gist
scratchservice.svc.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
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(); }
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.