개정판 c433ebde
gitignore 변경
Change-Id: Ia4787800e7d538cfdb63e92ce44a3f2001025da0
ConvertService/ServiceBase/ServiceTestApp/MainWindow.xaml.cs | ||
---|---|---|
26 | 26 |
using Markus.Service.Helper; |
27 | 27 |
using Markus.Service.DataBase; |
28 | 28 |
using Newtonsoft.Json; |
29 |
using System.Web.Script.Serialization; |
|
30 |
using System.Net.Http; |
|
29 | 31 |
|
30 | 32 |
namespace ServiceTestApp |
31 | 33 |
{ |
... | ... | |
434 | 436 |
station.GetApplicationConfig(); |
435 | 437 |
station.StartWcfService(); |
436 | 438 |
} |
439 |
private static readonly HttpClient _Client = new HttpClient(); |
|
440 |
private static JavaScriptSerializer _Serializer = new JavaScriptSerializer(); |
|
437 | 441 |
|
438 | 442 |
private async void WebServiceTest_click(object sender, RoutedEventArgs e) |
439 | 443 |
{ |
... | ... | |
441 | 445 |
|
442 | 446 |
var uri = new Uri("http://localhost:9101/StationService/Rest/GetConvertItem"); // string 을 Uri 로 형변환 |
443 | 447 |
var wReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri); // WebRequest 객체 형성 및 HttpWebRequest 로 형변환 |
444 |
wReq.Method = "GET"; // 전송 방법 "GET" or "POST" |
|
445 |
wReq.ServicePoint.Expect100Continue = false; |
|
446 |
wReq.CookieContainer = new System.Net.CookieContainer(); |
|
447 |
wReq.CookieContainer.SetCookies(uri, cookie); // 넘겨줄 쿠키가 있을때 CookiContainer 에 저장 |
|
448 |
wReq.Method = "POST"; // 전송 방법 "GET" or "POST" |
|
449 |
wReq.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; |
|
450 |
wReq.Proxy = new System.Net.WebProxy("127.0.0.1", 8888); |
|
451 |
//wReq.ServicePoint.Expect100Continue = false; |
|
452 |
//wReq.CookieContainer = new System.Net.CookieContainer(); |
|
453 |
//wReq.CookieContainer.SetCookies(uri, cookie); // 넘겨줄 쿠키가 있을때 CookiContainer 에 저장 |
|
448 | 454 |
|
449 | 455 |
//POST 전송일 경우 |
450 |
var data = new |
|
456 |
|
|
457 |
string url = "http://localhost:9101/StationService/Rest/GetConvertItem"; |
|
458 |
var data = new SEND |
|
451 | 459 |
{ |
452 | 460 |
ProjectNo = "111111", |
453 | 461 |
DocumentID = "453" |
454 | 462 |
}; |
455 |
var jsonRequest = JsonConvert.SerializeObject(data); |
|
456 |
|
|
457 |
byte[] byteArray = Encoding.UTF8.GetBytes(jsonRequest); |
|
458 |
|
|
459 |
Stream dataStream = wReq.GetRequestStream(); |
|
460 |
dataStream.Write(byteArray, 0, byteArray.Length); |
|
461 |
dataStream.Close(); |
|
462 | 463 |
|
464 |
var json = _Serializer.Serialize(data); |
|
465 |
var response2 = await Request(HttpMethod.Post, url, json, new Dictionary<string, string>()); |
|
466 |
string responseText = await response2.Content.ReadAsStringAsync(); |
|
463 | 467 |
|
464 |
using (var wRes = (System.Net.HttpWebResponse)wReq.GetResponse()) |
|
465 |
{ |
|
466 |
Stream respPostStream = wRes.GetResponseStream(); |
|
467 |
StreamReader readerPost = new StreamReader(respPostStream, Encoding.GetEncoding("EUC-KR"), true); |
|
468 |
|
|
469 |
var resResult = readerPost.ReadToEnd(); |
|
470 |
System.Diagnostics.Debug.WriteLine( resResult); |
|
471 |
} |
|
468 |
Console.WriteLine(responseText); |
|
472 | 469 |
|
473 | 470 |
|
474 | 471 |
using (var client = new System.Net.Http.HttpClient()) |
475 | 472 |
{ |
476 | 473 |
var uri2 = new Uri("http://localhost:9101/StationService/Rest/GetConvertItem"); |
477 |
var data2 = new |
|
474 |
|
|
475 |
var data2 = new SEND |
|
478 | 476 |
{ |
479 | 477 |
ProjectNo = "111111", |
480 | 478 |
DocumentID = "453" |
... | ... | |
490 | 488 |
System.Diagnostics.Debug.WriteLine(await response.Content.ReadAsStringAsync()); |
491 | 489 |
} |
492 | 490 |
} |
493 |
//var client = new System.Net.WebClient(); |
|
494 |
//var result = await client.DownloadStringTaskAsync("http://localhost:9101/StationService/Rest/GetConvertItem?ProjectNo=111111&DocumentID=453"); |
|
491 |
|
|
492 |
//var client2 = new System.Net.WebClient(); |
|
493 |
//client2.Proxy = new System.Net.WebProxy("127.0.0.1", 8888); |
|
494 |
//var result = await client2.DownloadStringTaskAsync("http://localhost:9101/StationService/Rest/GetConvertItem?ProjectNo=111111&DocumentID=453"); |
|
495 | 495 |
//System.Diagnostics.Debug.WriteLine(result); |
496 | 496 |
} |
497 |
|
|
498 |
static async Task<System.Net.Http.HttpResponseMessage> Request(HttpMethod pMethod, string pUrl, string pJsonContent, Dictionary<string, string> pHeaders) |
|
499 |
{ |
|
500 |
var httpRequestMessage = new HttpRequestMessage(); |
|
501 |
httpRequestMessage.Method = pMethod; |
|
502 |
httpRequestMessage.RequestUri = new Uri(pUrl); |
|
503 |
foreach (var head in pHeaders) |
|
504 |
{ |
|
505 |
httpRequestMessage.Headers.Add(head.Key, head.Value); |
|
506 |
} |
|
507 |
switch (pMethod.Method) |
|
508 |
{ |
|
509 |
case "POST": |
|
510 |
HttpContent httpContent = new StringContent(pJsonContent, Encoding.UTF8, "application/json"); |
|
511 |
httpRequestMessage.Content = httpContent; |
|
512 |
break; |
|
513 |
|
|
514 |
} |
|
515 |
|
|
516 |
return await new HttpClient().SendAsync(httpRequestMessage); |
|
517 |
} |
|
497 | 518 |
} |
498 | 519 |
|
499 | 520 |
class IntegratedServiceInstaller |
... | ... | |
559 | 580 |
SINST.Uninstall(null); |
560 | 581 |
} |
561 | 582 |
} |
583 |
|
|
584 |
public class SEND |
|
585 |
{ |
|
586 |
public string ProjectNo { get; set; } |
|
587 |
public string DocumentID{ get; set; } |
|
588 |
} |
|
562 | 589 |
} |
내보내기 Unified diff