我有一个托管在 IIS 上的 WCF 服务。这是我的界面:
[ServiceContract]
[SilverlightFaultBehavior]
public interface IETC
{
[OperationContract]
[PrincipalPermission(SecurityAction.Demand, Role = "XYZ")]
string GetStampXML();
[OperationContract]
[PrincipalPermission(SecurityAction.Demand, Role = "XYZ")]
List<Stamp> GetStamps();
}
通过 Web 浏览器访问 WCF 服务时出现错误。错误如下:
Type 'System.Windows.Media.ImageSource' cannot be serialized. Consider marking it with the DataContractAttribute attribute.....
我的邮票类别是:
[DataContract]
public class Stamp
{
private string _Name;
private string _SmallIcon = "";
private string _MediumIcon = "";
private string _LargeIcon = "";
private BitmapImage _SmallImage;
private BitmapImage _MediumImage;
private BitmapImage _LargeImage;
[DataMember]
public string Name
{
get { return _Name; }
set { _Name = value; }
}
[DataMember]
public string SmallIcon
{
get { return _SmallIcon; }
set { _SmallIcon = value; }
}
[DataMember]
public string MediumIcon
{
get { return _MediumIcon; }
set { _MediumIcon = value; }
}
[DataMember]
public string LargeIcon
{
get { return _LargeIcon; }
set { _LargeIcon = value; }
}
[IgnoreDataMember]
public BitmapImage SmallImage
{
get { return _SmallImage; }
set { _SmallImage = value; }
}
[IgnoreDataMember]
public BitmapImage MediumImage
{
get { return _MediumImage; }
set { _MediumImage = value; }
}
[IgnoreDataMember]
public BitmapImage LargeImage
{
get { return _LargeImage; }
set { _LargeImage = value; }
}
}
这就像 IgnoreDataMember 没有被识别。我在没有 IgnoreDataMember 数字的情况下尝试了它,它只会序列化 DataMember,但这也不起作用。任何想法为什么它似乎试图序列化 BitmapImage?