【发布时间】:2013-02-18 16:56:03
【问题描述】:
我尝试传输一个 DTO(WCF 客户端到 WCF 服务器),其中包含一个带有接口的子对象。
我的代码:
WCF 服务方法:
[OperationBehavior(TransactionScopeRequired = true)]
public void SendTest(MyTestDto testDto)
{
...
}
MyTestDto 类:
[Serializable]
[DataContract(Name = "MyTestDto")]
public class MyTestDto : ITestDto
{
[DataMember(IsRequired = true, Order = 1, Name = "MyTestDto")]
[DataMemberValidation(IsRequired = true)]
public ITest Test { get; set; }
}
ITest 接口:
public interface ITest
{
int Field1 {get;set;}
int Field2 {get;set,}
}
问题是,如果我将 MyTestDto 从服务器传输到客户端,我总是会得到一个FaultException。我分析了 WSDL 文件,测试字段的类型为:AnyType。我想,这就是问题所在。我已经用抽象类替换了ITest,因此通信正常(当然我必须用抽象类设置ServiceKnownType 属性)。
你能帮帮我吗?为什么它适用于抽象类而不适用于接口?
【问题讨论】: