I am using VS 2005 (C# ). My Webservice returns a type as follow :
[WebMethod]
public Employee getEmployee( )
{
Employee emp=new Employee();
emp.EmpID=1000;
emp.EmpName="Wallace";
return emp;
}
from Client side i have created a Proxy.
localhost.Service1 svc = new WindowsApplication1.localhost.Service1();
How can i get the Employee object returned by getEmployee() method.
Do i need to create a Employee class in client side ?
localhost.Service1 svc = new WindowsApplication1.localhost.Service1();
Employee emp = new Employee();
object obj= svc.getEmployee();
emp = (Employee)obj;
MessageBox.Show("Id=:" + emp.EmpID.ToString() + "," + "Name:=" + emp.EmpName);
By doing so also i am receiving casting error.
Why are you getting the Employee object in an object, cant you get it like this:
Localhost.Service1 svc = new WindowsApplication1.localhost.Service1();
**Employee employee= svc.getEmployee();**
MessageBox.Show("Id=:" + employee.EmpID.ToString() + "," + "Name:=" + employee.EmpName);
All you need is this:
using (localhost.Service1 svc = new WindowsApplication1.localhost.Service1())
{
localhost.Employee emp = svc.getEmployee();
MessageBox.Show("Id=:" + emp.EmpID.ToString() + "," + "Name:=" + emp.EmpName);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.