質問編集履歴
2
文法の修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
a
|
1
|
+
WCF Rest Service Applicationの実装について
|
test
CHANGED
@@ -1 +1,285 @@
|
|
1
|
+
解答がつかなかったためもう一度質問いたします。すみません。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
■.netFramework 3.5(もちろん当プロジェクトも対象は.net3.5)
|
6
|
+
|
7
|
+
■VisualStudio 2010
|
8
|
+
|
9
|
+
■SQLServer2014
|
10
|
+
|
11
|
+
■SQLServer Management Studio
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
Intra-martから送られてきた引数を使用して、DBの値を更新するプロジェクトを作成することになりました。
|
16
|
+
|
17
|
+
しかし1年目のPGであり、かつhttpresponse, request??系の製造には携わったことがなく言語もC#と手詰まり状態です。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
PUTのupdateメソッド文中に処理を記述すればいいのかなとは考えているのですが、記述後の接続方法が不明のため着手ができない状況です。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
またネット上にも有益な情報がないため、頼れる場所がここしかありません。他力本願で申し訳ありませんが、よろしくお願いいたします。
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
下記に詳細を記します。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
**■実装したいこと**
|
34
|
+
|
35
|
+
受け取った引数を使用してDBの値を一件更新。
|
36
|
+
|
37
|
+
【Intra-mart】
|
38
|
+
|
39
|
+
| ↑
|
40
|
+
|
41
|
+
引 HttpStatus
|
42
|
+
|
43
|
+
数 Code(正常:200, パラメータ不正:400, 異常:500,など)
|
44
|
+
|
45
|
+
↓ |
|
46
|
+
|
47
|
+
**プログラム(今回の成果物)**
|
48
|
+
|
49
|
+
| ↑
|
50
|
+
|
51
|
+
更 戻り
|
52
|
+
|
53
|
+
新 値
|
54
|
+
|
55
|
+
↓ |
|
56
|
+
|
57
|
+
【DataBase】
|
58
|
+
|
59
|
+
※更新はStoredProcedureで行う。
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
■引数(URLで送信されてくることは確実)
|
64
|
+
|
65
|
+
http://~~/{第1引数}/{第2引数}/{第3引数}
|
66
|
+
|
67
|
+
第1引数 : MODE
|
68
|
+
|
69
|
+
第2引数 : CODE
|
70
|
+
|
71
|
+
第3引数 : SUBCODE
|
72
|
+
|
73
|
+
※コード + サブコード で一意のデータになる。
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
■DB(例)
|
78
|
+
|
79
|
+
________________________
|
80
|
+
|
81
|
+
|**CODE** |**SUBCODE**| LIFEANDDEATH |**MODE**
|
82
|
+
|
83
|
+
|————————————————————————
|
84
|
+
|
85
|
+
|YAMADA| 00 | Dead |0
|
86
|
+
|
87
|
+
|—————————————————————————
|
88
|
+
|
89
|
+
|YAMADA| 01 | Dead |0
|
90
|
+
|
91
|
+
―――――――――――――――――――――――――
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
■更新例
|
96
|
+
|
97
|
+
第1引数:1 (1:「Living」or 2:「Die」or 3:「heaven」)
|
98
|
+
|
99
|
+
第2引数:YAMADA
|
100
|
+
|
101
|
+
第3引数:01
|
102
|
+
|
103
|
+
________________________
|
104
|
+
|
105
|
+
|CODE |SUBCODE| LIFEANDDEATH |MODE
|
106
|
+
|
107
|
+
|————————————————————————
|
108
|
+
|
109
|
+
|YAMADA| 00 | Dead |0
|
110
|
+
|
111
|
+
|—————————————————————————
|
112
|
+
|
113
|
+
|**YAMADA| 01 | Living |1**
|
114
|
+
|
115
|
+
―――――――――――――――――――――――――
|
116
|
+
|
117
|
+
→第1引数で「1」が送信されてきたので、CODE+SUBに該当するデータの
|
118
|
+
|
119
|
+
LIFEANDDEATHを「Living」に, MODEを第1引数の値(1)で更新する
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
【Service1.svc.cs】
|
128
|
+
|
129
|
+
```C#
|
130
|
+
|
131
|
+
using System;
|
132
|
+
|
133
|
+
using System.Collections.Generic;
|
134
|
+
|
135
|
+
using System.Linq;
|
136
|
+
|
137
|
+
using System.ServiceModel;
|
138
|
+
|
139
|
+
using System.ServiceModel.Activation;
|
140
|
+
|
141
|
+
using System.ServiceModel.Web;
|
142
|
+
|
143
|
+
using System.Text;
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
namespace WcfRestService6
|
148
|
+
|
149
|
+
{
|
150
|
+
|
151
|
+
// NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in the associated .svc file.
|
152
|
+
|
153
|
+
// NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want
|
154
|
+
|
155
|
+
// a single instance of the service to process all calls.
|
156
|
+
|
157
|
+
[ServiceContract]
|
158
|
+
|
159
|
+
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
|
160
|
+
|
161
|
+
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
|
162
|
+
|
163
|
+
public class Service1
|
164
|
+
|
165
|
+
{
|
166
|
+
|
167
|
+
// TODO: Implement the collection resource that will contain the SampleItem instances
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
[WebGet(UriTemplate = ""), OperationContract]
|
172
|
+
|
173
|
+
public List<SampleItem> GetCollection()
|
174
|
+
|
175
|
+
{
|
176
|
+
|
177
|
+
// TODO: Replace the current implementation to return a collection of SampleItem instances
|
178
|
+
|
179
|
+
return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello" } };
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
[WebInvoke(UriTemplate = "", Method = "POST"), OperationContract]
|
186
|
+
|
187
|
+
public SampleItem Create(SampleItem instance)
|
188
|
+
|
189
|
+
{
|
190
|
+
|
191
|
+
// TODO: Add the new instance of SampleItem to the collection
|
192
|
+
|
193
|
+
throw new NotImplementedException();
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
[WebGet(UriTemplate = "{id}"), OperationContract]
|
200
|
+
|
201
|
+
public SampleItem Get(string id)
|
202
|
+
|
203
|
+
{
|
204
|
+
|
205
|
+
// TODO: Return the instance of SampleItem with the given id
|
206
|
+
|
207
|
+
throw new NotImplementedException();
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
[WebInvoke(UriTemplate = "{id}", Method = "PUT"), OperationContract]
|
214
|
+
|
1
|
-
aaaa
|
215
|
+
public SampleItem Update(string id, SampleItem instance)
|
216
|
+
|
217
|
+
{
|
218
|
+
|
219
|
+
// TODO: Update the given instance of SampleItem in the collection
|
220
|
+
|
221
|
+
throw new NotImplementedException();
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
[WebInvoke(UriTemplate = "{id}", Method = "DELETE"), OperationContract]
|
228
|
+
|
229
|
+
public void Delete(string id)
|
230
|
+
|
231
|
+
{
|
232
|
+
|
233
|
+
// TODO: Remove the instance of SampleItem with the given id from the collection
|
234
|
+
|
235
|
+
throw new NotImplementedException();
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
```
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
【SampleItem.cs】
|
252
|
+
|
253
|
+
```C#
|
254
|
+
|
255
|
+
using System;
|
256
|
+
|
257
|
+
using System.Collections.Generic;
|
258
|
+
|
259
|
+
using System.Linq;
|
260
|
+
|
261
|
+
using System.Runtime.Serialization;
|
262
|
+
|
263
|
+
using System.Text;
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
namespace WcfRestService6
|
268
|
+
|
269
|
+
{
|
270
|
+
|
271
|
+
// TODO: Edit the SampleItem class
|
272
|
+
|
273
|
+
public class SampleItem
|
274
|
+
|
275
|
+
{
|
276
|
+
|
277
|
+
public int Id { get; set; }
|
278
|
+
|
279
|
+
public string StringValue { get; set; }
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
```
|
1
aa
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
aaaaaaa
|
test
CHANGED
@@ -1,249 +1 @@
|
|
1
|
-
**■VisualStudio 2010
|
2
|
-
|
3
|
-
■.netFrameWork3.5
|
4
|
-
|
5
|
-
■SQLServer2014(SQLServer Management Studio)**
|
6
|
-
|
7
|
-
上記環境にて開発を行っております。
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
今回intra-martから受け取った引数によって、DBを一件更新する処理を作ろうとしています。
|
12
|
-
|
13
|
-
【intra-mart】―――引数――→【今回作成するプログラム】――――更新(StoredProcedure)―――→【DB】
|
14
|
-
|
15
|
-
例:第1引数:1 or 2 or 3
|
16
|
-
|
17
|
-
第2引数:ワークID
|
18
|
-
|
19
|
-
第3引数:ワークSBNO
|
20
|
-
|
21
|
-
※ワークID + ワークSBNOで一意に決まるデータがある
|
22
|
-
|
23
|
-
戻り値 :下記HTTPステータスコード
|
24
|
-
|
25
|
-
200(正常終了)
|
26
|
-
|
27
|
-
400(パラメータ不正)
|
28
|
-
|
29
|
-
500(異常終了)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
_____________________
|
36
|
-
|
37
|
-
|WORK_ID |WORK_SBNO|STATUS|...
|
38
|
-
|
39
|
-
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
|
40
|
-
|
41
|
-
|A001 |00 |1 |...
|
42
|
-
|
43
|
-
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
|
44
|
-
|
45
|
-
|A001 |01 |1 |...
|
46
|
-
|
47
|
-
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
|
48
|
-
|
49
|
-
|..... |....... |... |...
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
【本題】
|
54
|
-
|
55
|
-
「http:~/1(第1引数)/A001(第2引数)/00(第2引数)」
|
56
|
-
|
57
|
-
このようなHTTPREQUEST??を受け取った場合に
|
58
|
-
|
59
|
-
第1引数が1なら
|
60
|
-
|
61
|
-
第2, 3引数で一意に決まったデータの「STATUS」を2に更新する。
|
62
|
-
|
63
|
-
というようなREST SERVICE APPLICATONを構築したいのですが、ネット上にもあまり有益な情報が転がっていなかったため質問いたしました。
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
【プロジェクトの作成方法】
|
68
|
-
|
69
|
-
新しいプロジェクトの追加→VisualC#→Webの中の「WCF REST Service 」Application
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
**【Service1.svc.cs(自動生成されるソース)】**
|
74
|
-
|
75
|
-
```ここに言語を入力
|
76
|
-
|
77
|
-
using System;
|
78
|
-
|
79
|
-
using System.Collections.Generic;
|
80
|
-
|
81
|
-
using System.Linq;
|
82
|
-
|
83
|
-
using System.ServiceModel;
|
84
|
-
|
85
|
-
using System.ServiceModel.Activation;
|
86
|
-
|
87
|
-
using System.ServiceModel.Web;
|
88
|
-
|
89
|
-
using System.Text;
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
namespace WcfRestService4
|
94
|
-
|
95
|
-
{
|
96
|
-
|
97
|
-
// NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in the associated .svc file.
|
98
|
-
|
99
|
-
// NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want
|
100
|
-
|
101
|
-
// a single instance of the service to process all calls.
|
102
|
-
|
103
|
-
[ServiceContract]
|
104
|
-
|
105
|
-
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
|
106
|
-
|
107
|
-
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
|
108
|
-
|
109
|
-
public class Service1
|
110
|
-
|
111
|
-
{
|
112
|
-
|
113
|
-
// TODO: Implement the collection resource that will contain the SampleItem instances
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
[WebGet(UriTemplate = ""), OperationContract]
|
118
|
-
|
119
|
-
public List<SampleItem> GetCollection()
|
120
|
-
|
121
|
-
{
|
122
|
-
|
123
|
-
// TODO: Replace the current implementation to return a collection of SampleItem instances
|
124
|
-
|
125
|
-
return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello" } };
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
[WebInvoke(UriTemplate = "", Method = "POST"), OperationContract]
|
132
|
-
|
133
|
-
public SampleItem Create(SampleItem instance)
|
134
|
-
|
135
|
-
{
|
136
|
-
|
137
|
-
// TODO: Add the new instance of SampleItem to the collection
|
138
|
-
|
139
|
-
throw new NotImplementedException();
|
140
|
-
|
141
|
-
}
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
[WebGet(UriTemplate = "{id}"), OperationContract]
|
146
|
-
|
147
|
-
public SampleItem Get(string id)
|
148
|
-
|
149
|
-
{
|
150
|
-
|
151
|
-
// TODO: Return the instance of SampleItem with the given id
|
152
|
-
|
153
|
-
throw new NotImplementedException();
|
154
|
-
|
155
|
-
}
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
[WebInvoke(UriTemplate = "{id}", Method = "PUT"), OperationContract]
|
160
|
-
|
161
|
-
|
1
|
+
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
162
|
-
|
163
|
-
{
|
164
|
-
|
165
|
-
// TODO: Update the given instance of SampleItem in the collection
|
166
|
-
|
167
|
-
throw new NotImplementedException();
|
168
|
-
|
169
|
-
}
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
[WebInvoke(UriTemplate = "{id}", Method = "DELETE"), OperationContract]
|
174
|
-
|
175
|
-
public void Delete(string id)
|
176
|
-
|
177
|
-
{
|
178
|
-
|
179
|
-
// TODO: Remove the instance of SampleItem with the given id from the collection
|
180
|
-
|
181
|
-
throw new NotImplementedException();
|
182
|
-
|
183
|
-
}
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
}
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
```
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
**【SampleItem.cs(自動生成されるソース)】**
|
198
|
-
|
199
|
-
```ここに言語を入力
|
200
|
-
|
201
|
-
using System;
|
202
|
-
|
203
|
-
using System.Collections.Generic;
|
204
|
-
|
205
|
-
using System.Linq;
|
206
|
-
|
207
|
-
using System.Runtime.Serialization;
|
208
|
-
|
209
|
-
using System.Text;
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
namespace WcfRestService4
|
214
|
-
|
215
|
-
{
|
216
|
-
|
217
|
-
// TODO: Edit the SampleItem class
|
218
|
-
|
219
|
-
public class SampleItem
|
220
|
-
|
221
|
-
{
|
222
|
-
|
223
|
-
public int Id { get; set; }
|
224
|
-
|
225
|
-
public string StringValue { get; set; }
|
226
|
-
|
227
|
-
}
|
228
|
-
|
229
|
-
}
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
```
|
234
|
-
|
235
|
-
何分PG1年目であり、HttpResponseRequest等の開発経験がないのでお手上げ状態です。
|
236
|
-
|
237
|
-
Updateメソッド呼び出して更新をかけるという理解であってるのかわからないですが、呼び出し方もデータの流れもわかっておりません。
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
コンソールアプリケーション、またはウェブブラウザ?からPUTメソッドを呼ぶことができれば、何とかなりそうだなと感じております。
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
送られてくるURLの形はまだ決定されていないので、とりあえずURLの形はよしなに自分で決めて作成できる状態です。
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
私の経験不足もああり、大変情報が不足していると思いますが、よろしくお願いいたします。
|