추가중….

var urlString = "http://localhost:19000/InsaDataService.svc/UploadFile";

var webClient = new WebClient();

Debug.WriteLine("업로드 시작");
webClient.UploadFileAsync(new Uri(urlString), "POST", @"C:\temp\img.JPG");
webClient.UploadProgressChanged += new UploadProgressChangedEventHandler(webClient_UploadProgressChanged);
webClient.UploadFileCompleted += new UploadFileCompletedEventHandler(webClient_UploadFileCompleted);

 

void webClient_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
{
    progressBar1.Value = e.ProgressPercentage;
}

void webClient_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e)
{
    if (e.Error != null)
    {
        MessageBox.Show(e.Error.Message);

        return;
    }
    string reply = System.Text.Encoding.UTF8.GetString(e.Result);
    XElement config = XElement.Parse(reply);
    string result = config.Value;


  
}

 

void webClient_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e)의 e.Result 결과값은 바이트로 넘어온다.

image

 

string reply = System.Text.Encoding.UTF8.GetString(e.Result); //문자열로 변환하면

아래와 같이 나온다. 나는 aefb3d66-b35d-4c99-b566-17e4f47f923a 이 값만 필요한데…..

image

 

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<UploadFile xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices">파일업로드 완료</UploadFile>

 

값 읽어오기

string reply = System.Text.Encoding.UTF8.GetString(e.Result);
XElement config = XElement.Parse(reply);
string result = config.Value;
result 의 결과 값 : aefb3d66-b35d-4c99-b566-17e4f47f923a

+ Recent posts