2009-02-07 3 views
0

클라이언트 쪽에서 데이터 집합을 암호화하고이를 웹 서비스로 보내고 암호 해독하는 방법을 보여주는 예제를 아는 사람이 있습니까?.Net 웹 서비스 암호 해독 데이터 집합

다른 질문 : 내가해야 할 일은 클라이언트에서 웹 서비스로 수백 행의 데이터를 보내고 웹 서비스에서이 레코드로 데이터베이스를 업데이트하도록하는 것입니다. 나는 데이터 셋을 사용하지 않고 이것을 할 수있는 다른 방법을 생각할 수 없다. 더 좋은 방법이 있습니까?

미리 감사드립니다.

답변

2

암호화에 관한 한, 왜 바퀴를 재발 명하려고합니까? SSL을 통한 웹 서비스에 연결하기 만하면 자체 개발 한 것보다 훨씬 안전합니다.

아마도 사용자 지정 구조체/개체를 만들고 해당 배열을 DataSet 대신 웹 서비스에 보냅니다. 그것은 (약간) 네트워크 트래픽을 의미합니다; webservice의 WSDL을보다 이해하기 쉽게 만들 것이다. 앞으로는 비 Microsoft 응용 프로그램이 웹 서비스와 쉽게 대화 할 수있게됩니다.

편집 : 예 ... 서버 측에서

사용자 정의 유형 (예를 들어, ExampleUser)를 선언 할 수 있습니다, 다음 설정 당신의 방법은 해당 유형의 배열을 수용하는 대신에 a 데이터 집합 :

[WebService(Namespace="http://example.yourdomain.com/ExampleWebService/")] 
public class ExampleWebService : System.Web.Services.WebService 
{ 
    // this is your custom type 
    public class ExampleUser 
    { 
     public int UserID { get; set; } 
     public string Name { get; set; } 
     public DateTime DateOfBirth { get; set; } 
    } 

    // this is your method 
    // accepts an array of ExampleUser rather than a DataSet 
    [WebMethod] 
    public void UploadUsers(ExampleUser[] usersArray) 
    { 
     // do something... 
    } 
} 

클라이언트 응용 프로그램에서 webservice에 대한 참조를 추가합니다. 위의 서버 측 코드에 선언 된 ExampleUser 유형을 사용할 수 있습니다.

그런 다음 바로 웹 서비스로 전송하기 전에 ExampleUser 객체의 배열에 데이터 집합을 변환 할 수 있습니다 :

// get the number of rows in the DataTable 
int rowCount = yourDataSet.Tables[0].Rows.Count; 

// create an array of ExampleUser with the correct capacity 
ExampleWebService.ExampleUser[] usersArray = 
    new ExampleWebService.ExampleUser[rowCount]; 

// iterate through each row in the table 
for (int i = 0; i < rowCount; i++) 
{ 
    DataRow dr = yourDataSet.Tables[0].Rows[i]; 

    // create an ExampleUser object and populate it from the DataRow columns 
    ExampleWebService.ExampleUser eu = new ExampleWebService.ExampleUser(); 
    eu.UserID = (int)dr["User_ID"]; 
    eu.Name = (string)dr["Name"]; 
    eu.DateOfBirth = (DateTime)dr["Date_Of_Birth"]; 

    // add the ExampleUser object to the array 
    usersArray[i] = eu; 
} 

// the array is populated so let's call the webservice 
ExampleWebService.UploadUsers(usersArray); 

편집 : 또 다른 예 ...

를 사용하는 경우. NET 3.5를 사용하면 LINQ와 객체 초기화 프로그램을 사용하여 몇 줄의 코드로 클라이언트 측을 가져올 수 있습니다.

// create and populate the array 
ExampleWebService.ExampleUser[] usersArray = 
    yourDataSet.Tables[0].AsEnumerable().Select 
    (
     s => new ExampleWebService.ExampleUser() 
     { 
      UserID = (int)s["User_ID"], 
      Name = (string)s["Name"], 
      DateOfBirth = (DateTime)s["Date_Of_Birth"] 
     } 
    ).ToArray(); 

// the array is populated so let's call the webservice 
ExampleWebService.UploadUsers(usersArray); 
+0

감사합니다. 그는 예입니다. 이것은 많은 도움이됩니다! – zSynopsis

0

글쎄, 여기에는 많은 접근법이 있습니다. 데이터를 XML 스트림에 기록한 다음 (이 작업은 DataSet이 수행하는 작업과 매우 유사합니다) 2) XML을 압축 할 수 있습니다 (압축률이 가장 좋음). 이 단계) 3) .NET 암호화 스키마 중 하나를 사용하여 암호화하고 마지막으로 4) XML을 DataSet 객체 또는 원하는대로 해독, 압축 해제 및 비 직렬화합니다.

참고로 암호화 결과를 Base64해야 할 수도 있습니다. 또 다른 대안은 SSL을 통해 웹 서비스를 암호화 및 사용하지 않고 해당 기본 암호화를 사용하는 것입니다. 데이터 유형에 따라 데이터 집합이 성능면에서 최상의 선택이 아닐 수도 있습니다. CSV 또는 JSON 스타일 데이터 블록을 보낼 수 있습니다. 특히 DataSet에 "DataTable"개체가 하나만있는 경우에는이 크기가 더 작아집니다. 이 중 많은 부분은 최상의 방법이 사용하는만큼 상황에 따라 다릅니다.