WCF代理生成

时间:2009-11-25 12:18:45

标签: c# proxy datacontract svcutil.exe

我正在使用svcutil工具生成代理。我的契约方法返回特定类型的对象。 但是生成的代理客户端接口具有object类型的返回值。 更有消息我得到了异常:

System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail] : The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:name. The InnerException message was 'XML 'Element' 'http://tempuri.org/:name' does not contain expected attribute 'http://schemas.microsoft.com/2003/10/Serialization/:Type'. The deserializer has no knowledge of which type to deserialize. Check that the type being serialized has the same contract as the type being deserialized.'.  Please see InnerException for more details.

任何想法发生了什么?

2 个答案:

答案 0 :(得分:0)

听起来svcutil在理解你的类型方面存在问题。如果您在其他程序集中定义了自定义类型,则可能需要使用[KnownType]属性来告诉svcutil发生了什么。

请参阅MSDN参考here

答案 1 :(得分:0)

嗯,我是WCF和项目的新手我正在探索......但是我刚刚注意到服务返回的数据类型没有用DataContract属性修饰。这是问题吗?