【发布时间】:2009-01-13 16:14:40
【问题描述】:
我在将枚举集合发送到 WCF 服务方法时遇到问题。我以这篇文章为指导:Sharing Enum with WCF Service
[ServiceContract]
[ServiceKnownType(typeof(MyEnum))]
[ServiceKnownType(typeof(List<MyEnum>))]
public interface IMyService{
[OperationContract]
MyEnum ServiceMethod1( );
[OperationContract]
IList<MyEnum> ServiceMethod2( );
[OperationContract]
IList<MyEnum> ServiceMethod3( MyEnum e );
[OperationContract]
IList<MyEnum> ServiceMethod4( IList<MyEnum> e );
}
[Serializable]
[DataContract]
public enum MyEnum{
[EnumMember] red,
[EnumMember] green,
[EnumMember] blue
};
ServiceMethod1、ServiceMethod2 和 ServiceMethod3 工作正常。尝试将枚举列表发送到 ServiceMethod4 时出现以下错误。
Operation 'ServiceMethod4' in contract 'IMyService' has a query variable named 'e' of type 'System.Collections.Generic.IList`1[MyEnum]', but type 'System.Collections.Generic.IList`1[MyEnum]' is not convertible by 'QueryStringConverter'. Variables for UriTemplate query values must have types that can be converted by 'QueryStringConverter'.
我需要创建自定义 QueryStringConverter 吗?
谢谢!
【问题讨论】:
标签: c# wcf collections enums