2013-02-17 3 views
1

그래서 C# 프로젝트에서 xml에 Linq를 사용하는 XML 문서 (학생 이름과 Id 이름 포함)를로드하고 관련 데이터 (기한, 금액 및 물건) WCF 서비스에서. 오른쪽 클릭만으로 서비스를 추가하고 서비스 참조를 추가 했으므로 배열을 GetData 함수에 전달해야합니다.이 함수는 초기화되었지만 null을 명시 적으로 전달해야합니다. 내 배열을 서비스 유형으로 변환 할 수 없으며 함수도 배열을 반환합니다. 어떻게 배열을 studentArray에 할당합니까?배열을 WCF 함수에 전달

ServiceReference1.ServiceClient client = new ServiceReference1.RycorServiceClient(); 

Application.ServiceReference1.Student[] studentArray = new ServiceReference1.Student[9]; 

     Student[] array = studentList.ToArray(); 

     //for (int i = 0; i <= array.Count(); i++) 
     // studentArray[i] = (RycorApplication.ServiceReference1.Student)array[i]; 

     //this gives me an error says Cannot convert type 'Application.Student' to 'Application.ServiceReference1.Student'. 

     var data = client.GetData(studentArray); 

이 데이터를 가져온 후이 데이터를 XML 파일에 어떻게 저장합니까?

답변

0

당신을 꽤을 ?

+0

왜냐하면, 내가하고있는 프로젝트, 그들은 이미 서비스를 주었고, 나는 wcf 서비스를 만들지 않았기 때문이다. –

+0

studentArray가 Empty이고 9의 빈 배열입니다. –

+0

덜 혼란스럽게 수정되었습니다 (잘하면). 기본적으로 내가 아는 유일한 방법은 이미 가지고있는 학생들의 배열을 반복하고 각 객체를 wcf 서비스가 기대하는 유형으로 변환하는 것입니다. –

1

Application.Student가 다른 유형이기 때문에이 오류가 발생합니다. Application.ServiceReference.Student를 사용하여 "studentList"유형 대신 Student 목록을 저장하려고 할 수 있습니다.

나는 Application.Student "목록"studentList이는 "한다고 가정하고 동일한 모델을 사용하거나 (첫 번째 대답) 같은 것을 사용하여 사이에 복사 할 수 있습니다 Copy values from one object to another

+0

불구하고 전체 개체를 전달하는 대신 그냥 WCF 호출을 변경하지 않는 이유는 학생 ID의 목록을 위해 당신이 할 수있는 경우에 질문을 내가해야합니까

List<ServiceReference1.Student> wcfStudentList = new System.Collections.Generic.List<ServiceReference1.Student>(); foreach (var student in studentList) { wcfStudentList.Add(new ServiceReference1.Student() { ID = student.ID, Name = student.Name, ..etc.. }); } var data = client.GetStudentData(wcfStudentList.ToArray()); 

: 많은이 작업을 수행해야 목록 studentList는 내가 만든 Student 클래스의 xml 파일에서로드 한 값 목록입니다. –

+0

studentArray가 비어 있습니다. 데이터를 얻기 위해 getdata funtion에서 학생 배열을 전달해야합니다. 학생 배열이 비어 있습니다. 오른쪽 right –

+0

문제는 콘텐츠가 아닙니다 (비어 있음). 문제는 그 유형입니다. Application.ServiceReference1.Student [] array = new ServiceReference1.Student [9];로 시도하십시오. – zapico

관련 문제