teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

文法の修正

2017/03/13 06:10

投稿

RI_KU
RI_KU

スコア24

title CHANGED
@@ -1,1 +1,1 @@
1
- aaaaaaa
1
+ WCF Rest Service Applicationの実装について
body CHANGED
@@ -1,1 +1,143 @@
1
+ 解答がつかなかったためもう一度質問いたします。すみません。
2
+
3
+ ■.netFramework 3.5(もちろん当プロジェクトも対象は.net3.5)
4
+ ■VisualStudio 2010
5
+ ■SQLServer2014
6
+ ■SQLServer Management Studio
7
+
8
+ Intra-martから送られてきた引数を使用して、DBの値を更新するプロジェクトを作成することになりました。
9
+ しかし1年目のPGであり、かつhttpresponse, request??系の製造には携わったことがなく言語もC#と手詰まり状態です。
10
+
11
+ PUTのupdateメソッド文中に処理を記述すればいいのかなとは考えているのですが、記述後の接続方法が不明のため着手ができない状況です。
12
+
13
+ またネット上にも有益な情報がないため、頼れる場所がここしかありません。他力本願で申し訳ありませんが、よろしくお願いいたします。
14
+
15
+ 下記に詳細を記します。
16
+
17
+ **■実装したいこと**
18
+ 受け取った引数を使用してDBの値を一件更新。
19
+ 【Intra-mart】
20
+ | ↑
21
+ 引 HttpStatus
22
+ 数 Code(正常:200, パラメータ不正:400, 異常:500,など)
23
+ ↓ |
24
+ **プログラム(今回の成果物)**
25
+ | ↑
26
+ 更 戻り
27
+ 新 値
28
+ ↓ |
29
+ 【DataBase】
30
+ ※更新はStoredProcedureで行う。
31
+
32
+ ■引数(URLで送信されてくることは確実)
33
+ http://~~/{第1引数}/{第2引数}/{第3引数}
34
+ 第1引数 : MODE
35
+ 第2引数 : CODE
36
+ 第3引数 : SUBCODE
37
+ ※コード + サブコード で一意のデータになる。
38
+
39
+ ■DB(例)
40
+ ________________________
41
+ |**CODE** |**SUBCODE**| LIFEANDDEATH |**MODE**
42
+ |————————————————————————
43
+ |YAMADA| 00 | Dead |0
44
+ |—————————————————————————
45
+ |YAMADA| 01 | Dead |0
46
+ ―――――――――――――――――――――――――
47
+
48
+ ■更新例
49
+ 第1引数:1 (1:「Living」or 2:「Die」or 3:「heaven」)
50
+ 第2引数:YAMADA
51
+ 第3引数:01
52
+ ________________________
53
+ |CODE |SUBCODE| LIFEANDDEATH |MODE
54
+ |————————————————————————
55
+ |YAMADA| 00 | Dead |0
56
+ |—————————————————————————
57
+ |**YAMADA| 01 | Living |1**
58
+ ―――――――――――――――――――――――――
59
+ →第1引数で「1」が送信されてきたので、CODE+SUBに該当するデータの
60
+ LIFEANDDEATHを「Living」に, MODEを第1引数の値(1)で更新する
61
+
62
+
63
+
64
+ 【Service1.svc.cs】
65
+ ```C#
66
+ using System;
67
+ using System.Collections.Generic;
68
+ using System.Linq;
69
+ using System.ServiceModel;
70
+ using System.ServiceModel.Activation;
71
+ using System.ServiceModel.Web;
72
+ using System.Text;
73
+
74
+ namespace WcfRestService6
75
+ {
76
+ // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in the associated .svc file.
77
+ // NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want
78
+ // a single instance of the service to process all calls.
79
+ [ServiceContract]
80
+ [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
81
+ [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
82
+ public class Service1
83
+ {
84
+ // TODO: Implement the collection resource that will contain the SampleItem instances
85
+
86
+ [WebGet(UriTemplate = ""), OperationContract]
87
+ public List<SampleItem> GetCollection()
88
+ {
89
+ // TODO: Replace the current implementation to return a collection of SampleItem instances
90
+ return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello" } };
91
+ }
92
+
93
+ [WebInvoke(UriTemplate = "", Method = "POST"), OperationContract]
94
+ public SampleItem Create(SampleItem instance)
95
+ {
96
+ // TODO: Add the new instance of SampleItem to the collection
97
+ throw new NotImplementedException();
98
+ }
99
+
100
+ [WebGet(UriTemplate = "{id}"), OperationContract]
101
+ public SampleItem Get(string id)
102
+ {
103
+ // TODO: Return the instance of SampleItem with the given id
104
+ throw new NotImplementedException();
105
+ }
106
+
107
+ [WebInvoke(UriTemplate = "{id}", Method = "PUT"), OperationContract]
1
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
108
+ public SampleItem Update(string id, SampleItem instance)
109
+ {
110
+ // TODO: Update the given instance of SampleItem in the collection
111
+ throw new NotImplementedException();
112
+ }
113
+
114
+ [WebInvoke(UriTemplate = "{id}", Method = "DELETE"), OperationContract]
115
+ public void Delete(string id)
116
+ {
117
+ // TODO: Remove the instance of SampleItem with the given id from the collection
118
+ throw new NotImplementedException();
119
+ }
120
+
121
+ }
122
+ }
123
+
124
+ ```
125
+
126
+ 【SampleItem.cs】
127
+ ```C#
128
+ using System;
129
+ using System.Collections.Generic;
130
+ using System.Linq;
131
+ using System.Runtime.Serialization;
132
+ using System.Text;
133
+
134
+ namespace WcfRestService6
135
+ {
136
+ // TODO: Edit the SampleItem class
137
+ public class SampleItem
138
+ {
139
+ public int Id { get; set; }
140
+ public string StringValue { get; set; }
141
+ }
142
+ }
143
+ ```

1

aa

2017/03/13 06:10

投稿

RI_KU
RI_KU

スコア24

title CHANGED
@@ -1,1 +1,1 @@
1
- WCF Rest Service Applicationの実装について
1
+ aaaaaaa
body CHANGED
@@ -1,125 +1,1 @@
1
- **■VisualStudio 2010
2
- ■.netFrameWork3.5
3
- ■SQLServer2014(SQLServer Management Studio)**
4
- 上記環境にて開発を行っております。
5
-
6
- 今回intra-martから受け取った引数によって、DBを一件更新する処理を作ろうとしています。
7
- 【intra-mart】―――引数――→【今回作成するプログラム】――――更新(StoredProcedure)―――→【DB】
8
- 例:第1引数:1 or 2 or 3
9
- 第2引数:ワークID
10
- 第3引数:ワークSBNO
11
- ※ワークID + ワークSBNOで一意に決まるデータがある
12
- 戻り値 :下記HTTPステータスコード
13
- 200(正常終了)
14
- 400(パラメータ不正)
15
- 500(異常終了)
16
-
17
-
18
- _____________________
19
- |WORK_ID |WORK_SBNO|STATUS|...
20
-  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
21
- |A001 |00 |1 |...
22
-  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
23
- |A001 |01 |1 |...
24
-  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
25
- |..... |....... |... |...
26
-
27
- 【本題】
28
- 「http:~/1(第1引数)/A001(第2引数)/00(第2引数)」
29
- このようなHTTPREQUEST??を受け取った場合に
30
- 第1引数が1なら
31
- 第2, 3引数で一意に決まったデータの「STATUS」を2に更新する。
32
- というようなREST SERVICE APPLICATONを構築したいのですが、ネット上にもあまり有益な情報が転がっていなかったため質問いたしました。
33
-
34
- 【プロジェクトの作成方法】
35
- 新しいプロジェクトの追加→VisualC#→Webの中の「WCF REST Service 」Application
36
-
37
- **【Service1.svc.cs(自動生成されるソース)】**
38
- ```ここに言語を入力
39
- using System;
40
- using System.Collections.Generic;
41
- using System.Linq;
42
- using System.ServiceModel;
43
- using System.ServiceModel.Activation;
44
- using System.ServiceModel.Web;
45
- using System.Text;
46
-
47
- namespace WcfRestService4
48
- {
49
- // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in the associated .svc file.
50
- // NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want
51
- // a single instance of the service to process all calls.
52
- [ServiceContract]
53
- [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
54
- [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
55
- public class Service1
56
- {
57
- // TODO: Implement the collection resource that will contain the SampleItem instances
58
-
59
- [WebGet(UriTemplate = ""), OperationContract]
60
- public List<SampleItem> GetCollection()
61
- {
62
- // TODO: Replace the current implementation to return a collection of SampleItem instances
63
- return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello" } };
64
- }
65
-
66
- [WebInvoke(UriTemplate = "", Method = "POST"), OperationContract]
67
- public SampleItem Create(SampleItem instance)
68
- {
69
- // TODO: Add the new instance of SampleItem to the collection
70
- throw new NotImplementedException();
71
- }
72
-
73
- [WebGet(UriTemplate = "{id}"), OperationContract]
74
- public SampleItem Get(string id)
75
- {
76
- // TODO: Return the instance of SampleItem with the given id
77
- throw new NotImplementedException();
78
- }
79
-
80
- [WebInvoke(UriTemplate = "{id}", Method = "PUT"), OperationContract]
81
- public SampleItem Update(string id, SampleItem instance)
1
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
82
- {
83
- // TODO: Update the given instance of SampleItem in the collection
84
- throw new NotImplementedException();
85
- }
86
-
87
- [WebInvoke(UriTemplate = "{id}", Method = "DELETE"), OperationContract]
88
- public void Delete(string id)
89
- {
90
- // TODO: Remove the instance of SampleItem with the given id from the collection
91
- throw new NotImplementedException();
92
- }
93
-
94
- }
95
- }
96
-
97
- ```
98
-
99
- **【SampleItem.cs(自動生成されるソース)】**
100
- ```ここに言語を入力
101
- using System;
102
- using System.Collections.Generic;
103
- using System.Linq;
104
- using System.Runtime.Serialization;
105
- using System.Text;
106
-
107
- namespace WcfRestService4
108
- {
109
- // TODO: Edit the SampleItem class
110
- public class SampleItem
111
- {
112
- public int Id { get; set; }
113
- public string StringValue { get; set; }
114
- }
115
- }
116
-
117
- ```
118
- 何分PG1年目であり、HttpResponseRequest等の開発経験がないのでお手上げ状態です。
119
- Updateメソッド呼び出して更新をかけるという理解であってるのかわからないですが、呼び出し方もデータの流れもわかっておりません。
120
-
121
- コンソールアプリケーション、またはウェブブラウザ?からPUTメソッドを呼ぶことができれば、何とかなりそうだなと感じております。
122
-
123
- 送られてくるURLの形はまだ決定されていないので、とりあえずURLの形はよしなに自分で決めて作成できる状態です。
124
-
125
- 私の経験不足もああり、大変情報が不足していると思いますが、よろしくお願いいたします。