forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChangeRequestService.cs
More file actions
97 lines (82 loc) · 2.57 KB
/
ChangeRequestService.cs
File metadata and controls
97 lines (82 loc) · 2.57 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System.Collections.Specialized;
using System.Web;
using ServiceStack;
namespace Check.ServiceInterface
{
[Route("/changerequest/{Id}")]
public class ChangeRequest
{
public string Id { get; set; }
}
public class ChangeRequestResponse
{
public string ContentType { get; set; }
public string Header { get; set; }
public string QueryString { get; set; }
public string Form { get; set; }
public ResponseStatus ResponseStatus { get; set; }
}
public class CustomHttpRequest : HttpRequestBase
{
private readonly HttpRequestBase original;
private readonly NameValueCollection queryString = new NameValueCollection();
private readonly NameValueCollection formData = new NameValueCollection();
public CustomHttpRequest(object original)
{
this.original = (HttpRequestBase)original;
this.original.ContentType = this.original.ContentType;
foreach (string key in this.original.QueryString.Keys)
{
queryString[key] = this.original.QueryString[key];
}
foreach (string key in this.original.Form.Keys)
{
formData[key] = this.original.Form[key];
}
}
public override string ContentType
{
get
{
return original.ContentType;
}
set
{
original.ContentType = value;
}
}
public override NameValueCollection QueryString
{
get { return queryString; }
}
public override NameValueCollection Form
{
get { return formData; }
}
public override NameValueCollection Headers
{
get
{
return original.Headers;
}
}
}
public class ChangeRequestService : Service
{
public object Any(ChangeRequest request)
{
var aspReq = new CustomHttpRequest(base.Request.OriginalRequest) {
ContentType = MimeTypes.FormUrlEncoded
};
aspReq.QueryString["Id"] = request.Id;
aspReq.Form["Id"] = request.Id;
aspReq.Headers["Id"] = request.Id;
return new ChangeRequestResponse {
ContentType = aspReq.ContentType,
Header = aspReq.Headers["Id"],
QueryString = aspReq.QueryString["Id"],
Form = aspReq.Form["Id"],
};
}
}
}