1

我在 wcf 服务中有一个类,用于表示一组无效参数,

[DataContract(Namespace = WebServiceNamespace.WsNamespace)]
public class InvalidParameterFault : FaultBase
{
    public override string GetReason()
    {
        return Resources.OneOrMoreParametersInvalid;
    }                       

    [DataMember]
    public string[] InvalidParameters { get; set; }       

    public InvalidParameterFault()
    {            
    }        
}

合同的(部分)定义为,

[FaultContract(typeof(InvalidParameterFault))]
[OperationContract]        
uint RegisterIndividual(RegisterIndividualPayload payload);

当我向我的测试项目添加服务引用时,它创建的包装器如下(与原始定义不同)。有人知道为什么吗 ?????????

[System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlSchemaProviderAttribute("ExportSchema")]
    public partial class InvalidParameterFault : object, System.Xml.Serialization.IXmlSerializable, System.ComponentModel.INotifyPropertyChanged {

        private System.Xml.XmlNode[] nodesField;

        private static System.Xml.XmlQualifiedName typeName = new System.Xml.XmlQualifiedName("InvalidParameterFault", "http://schemas.facecode.com/webservices/2009/08/");

        public System.Xml.XmlNode[] Nodes {
            get {
                return this.nodesField;
            }
            set {
                if ((object.ReferenceEquals(this.nodesField, value) != true)) {
                    this.nodesField = value;
                    this.RaisePropertyChanged("Nodes");
                }
            }
        }

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        public void ReadXml(System.Xml.XmlReader reader) {
            this.nodesField = System.Runtime.Serialization.XmlSerializableServices.ReadNodes(reader);
        }

        public void WriteXml(System.Xml.XmlWriter writer) {
            System.Runtime.Serialization.XmlSerializableServices.WriteNodes(writer, this.Nodes);
        }

        public System.Xml.Schema.XmlSchema GetSchema() {
            return null;
        }

        public static System.Xml.XmlQualifiedName ExportSchema(System.Xml.Schema.XmlSchemaSet schemas) {
            System.Runtime.Serialization.XmlSerializableServices.AddDefaultSchema(schemas, typeName);
            return typeName;
        }

        protected void RaisePropertyChanged(string propertyName) {
            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
            if ((propertyChanged != null)) {
                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
        }
    }
4

1 回答 1

1

假设您使用的是 Visual Studio,“添加服务引用”->“高级”对话框中有一些设置允许您指定生成集合的类型。是设置生成 System.Array (我认为是默认值)还是其他?

此外,这个部分类似乎根本不是从 FaultBase 派生的。您是否可能选择了“添加 Web 引用”——说服 Visual Studio 实现经典样式的 ASMX Web 服务客户端而不是 WCF 客户端?

于 2010-03-06T06:51:16.880 回答