解答がつかなかったためもう一度質問いたします。すみません。
■.netFramework 3.5(もちろん当プロジェクトも対象は.net3.5)
■VisualStudio 2010
■SQLServer2014
■SQLServer Management Studio
Intra-martから送られてきた引数を使用して、DBの値を更新するプロジェクトを作成することになりました。
しかし1年目のPGであり、かつhttpresponse, request??系の製造には携わったことがなく言語もC#と手詰まり状態です。
PUTのupdateメソッド文中に処理を記述すればいいのかなとは考えているのですが、記述後の接続方法が不明のため着手ができない状況です。
またネット上にも有益な情報がないため、頼れる場所がここしかありません。他力本願で申し訳ありませんが、よろしくお願いいたします。
下記に詳細を記します。
■実装したいこと
受け取った引数を使用してDBの値を一件更新。
【Intra-mart】
| ↑
引 HttpStatus
数 Code(正常:200, パラメータ不正:400, 異常:500,など)
↓ |
プログラム(今回の成果物)
| ↑
更 戻り
新 値
↓ |
【DataBase】
※更新はStoredProcedureで行う。
■引数(URLで送信されてくることは確実)
http://~~/{第1引数}/{第2引数}/{第3引数}
第1引数 : MODE
第2引数 : CODE
第3引数 : SUBCODE
※コード + サブコード で一意のデータになる。
■DB(例)
________________________
|CODE |SUBCODE| LIFEANDDEATH |MODE
|————————————————————————
|YAMADA| 00 | Dead |0
|—————————————————————————
|YAMADA| 01 | Dead |0
―――――――――――――――――――――――――
■更新例
第1引数:1 (1:「Living」or 2:「Die」or 3:「heaven」)
第2引数:YAMADA
第3引数:01
________________________
|CODE |SUBCODE| LIFEANDDEATH |MODE
|————————————————————————
|YAMADA| 00 | Dead |0
|—————————————————————————
|YAMADA| 01 | Living |1
―――――――――――――――――――――――――
→第1引数で「1」が送信されてきたので、CODE+SUBに該当するデータの
LIFEANDDEATHを「Living」に, MODEを第1引数の値(1)で更新する
【Service1.svc.cs】
C#
1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.ServiceModel; 5using System.ServiceModel.Activation; 6using System.ServiceModel.Web; 7using System.Text; 8 9namespace WcfRestService6 10{ 11 // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in the associated .svc file. 12 // NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want 13 // a single instance of the service to process all calls. 14 [ServiceContract] 15 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 16 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] 17 public class Service1 18 { 19 // TODO: Implement the collection resource that will contain the SampleItem instances 20 21 [WebGet(UriTemplate = ""), OperationContract] 22 public List<SampleItem> GetCollection() 23 { 24 // TODO: Replace the current implementation to return a collection of SampleItem instances 25 return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello" } }; 26 } 27 28 [WebInvoke(UriTemplate = "", Method = "POST"), OperationContract] 29 public SampleItem Create(SampleItem instance) 30 { 31 // TODO: Add the new instance of SampleItem to the collection 32 throw new NotImplementedException(); 33 } 34 35 [WebGet(UriTemplate = "{id}"), OperationContract] 36 public SampleItem Get(string id) 37 { 38 // TODO: Return the instance of SampleItem with the given id 39 throw new NotImplementedException(); 40 } 41 42 [WebInvoke(UriTemplate = "{id}", Method = "PUT"), OperationContract] 43 public SampleItem Update(string id, SampleItem instance) 44 { 45 // TODO: Update the given instance of SampleItem in the collection 46 throw new NotImplementedException(); 47 } 48 49 [WebInvoke(UriTemplate = "{id}", Method = "DELETE"), OperationContract] 50 public void Delete(string id) 51 { 52 // TODO: Remove the instance of SampleItem with the given id from the collection 53 throw new NotImplementedException(); 54 } 55 56 } 57} 58
【SampleItem.cs】
C#
1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Runtime.Serialization; 5using System.Text; 6 7namespace WcfRestService6 8{ 9 // TODO: Edit the SampleItem class 10 public class SampleItem 11 { 12 public int Id { get; set; } 13 public string StringValue { get; set; } 14 } 15}
あなたの回答
tips
プレビュー