-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTutorialService.svc.cs
75 lines (62 loc) · 2.69 KB
/
TutorialService.svc.cs
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
namespace Webservice.REST
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class TutorialService
{
private static List<String> first = new List<String>
(new String[] { "Arrays", "Queues", "Stacks" });
// To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
// To create an operation that returns XML,
// add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
// and include the following line in the operation body:
// WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
// Used to define how we can call this method via URL
[WebGet(UriTemplate = "/Tutorial")]
// This section of code will go through the list of strings in the "first" variable and return all of them
public String GetAllTutorial()
{
int count = first.Count;
String TutorialList = "";
for (int i = 0; i < count; i++)
TutorialList = TutorialList + first[i] + ",";
return TutorialList;
}
// Getting the web service by ID
[WebGet(UriTemplate = "/Tutorial/{Tutorialid}")]
public String GetTutorialbyID(String Tutorialid)
{
int pid;
// int32 function is used to convert the string variable of Tutorialid to an integer
Int32.TryParse(Tutorialid, out pid);
return first[pid];
}
// Invoke method and specifying the POST method
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json,
UriTemplate = "/Tutorial", ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)]
public void AddTutorial(String str)
{
first.Add(str);
}
// Invoke POST method and specifying the Delete parameter
[WebInvoke(Method = "DELETE", RequestFormat = WebMessageFormat.Json,
UriTemplate = "/Tutorial/{Tutorialid}", ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)]
public void DeleteTutorial(String Tutorialid)
{
int pid;
// int32 function is used to convert the string variable of Tutorialid to an integer
Int32.TryParse(Tutorialid, out pid);
first.RemoveAt(pid);
}
}
}