【发布时间】:2010-10-04 00:27:30
【问题描述】:
我需要从 web 服务返回一个复杂类型,并构建了实现 IMyComplexType 接口的 MyComplexType 类。现在在我的网络服务中,我有一个方法应该返回一个实现 IMyComplexType 的对象,如下所示:
[WebMethod]
public IMyComplexType GetMyComplexType()
{
IMyComplexType myCt = new MyComplexType();
...
return myCt;
}
一切都可以编译,但是当我运行 web 服务时,它会抛出如下异常:
System.NotSupportedException: Cannot serialize interface MyWebService.IMyComplexType.
这是设计使然还是我遗漏了什么。我可以以某种方式装饰我的班级或界面以允许这样做吗?我是否必须消除所有接口,只使用具体的或抽象的基类才能使用 .net webservices 做到这一点?
编辑:
这是我要序列化的接口:
public interface ICustomer
{
long Id {get; set;}
string Name {get; set;}
string EmailAddress {get; set;}
}
【问题讨论】:
标签: .net web-services interface