1

我认为这是我遇到的一个奇怪问题,我在服务器端定义了一些类,然后我通过服务引用对其进行引用,其中两个正在按应有的方式工作。我已经从服务接口中指定了已知类型:

[ServiceKnownType(typeof(Obj))]
[ServiceKnownType(typeof(DigitalObject))]
[ServiceKnownType(typeof(AnalogueObject))]
[ServiceKnownType(typeof(AttributeType))]
[ServiceKnownType(typeof(AttributeData))]

然后,从 silverlight 应用程序中,我通过以下方式引用该类:

private ServiceReference.AttributeData commonData = new ServiceReference.AttributeData();

这工作正常,但是我对另一个类做同样的事情,唯一的区别是类命名AnalogueObjectDigitalObject派生自 type 类Obj。你知道发生了什么吗?命名空间都是一样的,我已经重建了 Web 解决方案并更新了服务引用。

示例类:

using System.ComponentModel;

namespace CapCon2
{
    public class Obj : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;    
        private string _Description;  
        public string ID { get; set; }    
        public string Description
        {
            get { return _Description; }
            set
            {
                _Description = value;
                NotifyPropertyChanged("Description");
            }
        }    
        public void NotifyPropertyChanged(string name)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }
    }
}

    public class AttributeData : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    private string _Description;

    public string ID { get; set; }

    public string Description 
    {
        get { return _Description; }
        set 
        {
            _Description = value;
            NotifyPropertyChanged("Description");
        }
    }

    public string Attribute { get; set; }

    public string DataType { get; set; }

    public string Input_InputSource { get; set; }

    public string Output_OutputDest { get; set; }

    public void NotifyPropertyChanged(string name)
    {
        if (PropertyChanged!= null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(name));
        }
    }
}
4

1 回答 1

1

如果您要在服务器和客户端之间传递一个复杂类型,那么您应该用DataContract属性标记它并用DataMember. 这将告诉 .NET 序列化对象并将其传递到 SOAP 消息中。

于 2012-05-01T09:43:22.107 回答