我正在使用VS 2005(C#)。我的Webservice返回一个类型如下:
[WebMethod]
public Employee getEmployee( )
{
Employee emp=new Employee();
emp.EmpID=1000;
emp.EmpName="Wallace";
return emp;
}
从客户端我创建了一个代理。
localhost.Service1 svc = new WindowsApplication1.localhost.Service1();
如何获取getEmployee()方法返回的Employee对象。
我是否需要在客户端创建一个Employee类?
....喜欢......
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);
通过这样做我也收到了投射错误。
答案 0 :(得分:0)
为什么要在对象中获取Employee对象,可以这样得到它:
Localhost.Service1 svc = new WindowsApplication1.localhost.Service1();
**Employee employee= svc.getEmployee();**
MessageBox.Show("Id=:" + employee.EmpID.ToString() + "," + "Name:=" + employee.EmpName);
答案 1 :(得分:0)
所有你需要的是:
using (localhost.Service1 svc = new WindowsApplication1.localhost.Service1())
{
localhost.Employee emp = svc.getEmployee();
MessageBox.Show("Id=:" + emp.EmpID.ToString() + "," + "Name:=" + emp.EmpName);
}