views:

73

answers:

2

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 ?

.... like ...

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.

A: 

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);
Bhaskar
Why are you creating `emp`?
John Saunders
I agree, emp is not at all needed, sorry i copied his code.
Bhaskar
A: 

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);
}
John Saunders
Yes.It yeild the result what i expected.I am a beginner,so i yet to learn a lot.