암호화에 관한 한, 왜 바퀴를 재발 명하려고합니까? 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);
감사합니다. 그는 예입니다. 이것은 많은 도움이됩니다! – zSynopsis