Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My requirement is to convert the response received from a SAP web-service to a generic list so that i can loop through the received records. i have been trying to look for the solution from a number of days but i am unable to find any.

Any solution which can execute the following will be really helpful.

Converting SAP web-service response to a Generic list of a customer class type.
Converting SAP web-service response to a Data Table.
Looping through the received records in SAP web-service response.

C#
public C_WebRequest Get_Employee(string Employee_Number) 
{ 
Z_GETEMPLOYEE empno = new Z_GETEMPLOYEE();
empno.I_EMP_NO = Employee_Number;
 

Z_GETEMPLOYEEResponse received;
NetworkCredential credentials = new NetworkCredential("username", "pass");
 
ZWS_GetEmployees objRequest = new ZWS_GetEmployees();
objRequest.Credentials = credentials; 

received = objRequest.Z_GETEMPLOYEE(empno);
 

C_WebRequest objRec_Emp = new C_WebRequest();
 
objRec_Emp.EMP_NO = Convert.ToInt32(Employee_Number);
objRec_Emp.ENGLISH_NAME = received.ENGLISH_NAME;
objRec_Emp.EMP_DATE = DateTime.Parse(received.EMP_DATE);
objRec_Emp.COUNT_BIRTH = received.COUNT_BIRTH;
objRec_Emp.COUNT_BIRTH_D = received.COUNT_BIRTH_D;
objRec_Emp.NATION_ID = received.NATION_ID;
objRec_Emp.NATION_ID_D = received.NATION_ID_D;
objRec_Emp.MARITAL_STATUS_ID = received.MARITAL_STATUS_ID;
objRec_Emp.MARITAL_STATUS_ID_D = received.MARITAL_STATUS_ID_D;
objRec_Emp.A_JOB_ID = Convert.ToInt32(received.A_JOB_ID);
 
return objRec_Emp;
}

I have added the Web service as a service reference in my project and used the above code to fetch if only one record is returned by the web Service. How can i loop if more then one records are returned by the web-service and convert them into a Generic List.
Posted
Comments
_Vitor Garcia_ 9-Feb-15 9:24am    
You could add objRec_Emp or Z_GETEMPLOYEEResponse to your Generic List and then for each it :

For each Emp as Z_GETEMPLOYEEResponse in _MyGenericList
'do whatever you want with each element Emp
msgbox.show(Emp.ENGLISH_NAME)
next


or maybe query your generic colection using Linq.
johannesnestler 9-Feb-15 10:17am    
Hi, I don't understand your question and guessing what your types do is boring. E.g what is C_WebRequest - it looks like the "custom type" you want and not a "Request" (maybe just bad naming). So please clarify what's your exact Problem - because if you can construct one object of a custom type for your Response from the SAP Service, I can not imagine what hinders you to collect them in a list. Maybe sorting your thoughts would help? Break it down in smaller/better steps. 1. Prepare call to web Service. 2. call Service and get reponse. 3. Parse/Transform/Project (whatever is needed) the raw Response to your custom type. 4. If Response contains multiple records - create the list directly from the Response, otherwise collect them after each call...
Aamir Latef 11-Feb-15 13:10pm    
How to create the list directly from the Response that is where I am facing problem. I am unable to do that..
Kuthuparakkal 9-Feb-15 11:19am    
Use reflection and loop through properties (recieved), get value and if you see the same property in your object (objRec_Emp) and assign the value. Is this you meant ?
Aamir Latef 12-Feb-15 15:59pm    
No i want to copy all the received records (from received object) to my custome class object (objRec_Emp) as a list.
i appologize if i am unable to make you clear my requirement .. my english is not that good.
i really appriciate your concern and attempt to help on finding a solution for me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900