如何在WCF服务中公开我的WSDL对象

时间:2017-06-16 15:57:33

标签: c# wcf wsdl datacontractserializer

我有一个WCF服务,它充当第三方服务的代理。

我已经向第三方WSDL端点添加了一个服务引用,现在我的reference.cs文件中有许多对象,我希望从我的WCF服务器公开,这些对象可以被我的服务请求使用。

例如;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.2046.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.opentravel.org/OTA/2003/05")]
public partial class OTA_HotelAvailRQ : object, System.ComponentModel.INotifyPropertyChanged
{

   private string echoTokenField;

   private System.DateTime timeStampField;

   private bool timeStampFieldSpecified;

   private bool targetFieldSpecified;

   private decimal versionField;

   private bool availRatesOnlyField;

   private bool availRatesOnlyFieldSpecified;

   [System.Xml.Serialization.XmlAttributeAttribute()]
   public string EchoToken
   {
       get
       {
           return this.echoTokenField;
       }
       set
       {
           this.echoTokenField = value;
           this.RaisePropertyChanged("EchoToken");
       }
   }

   /// <remarks/>
   [System.Xml.Serialization.XmlAttributeAttribute()]
   public System.DateTime TimeStamp
   {
       get
       {
           return this.timeStampField;
       }
       set
       {
           this.timeStampField = value;
          this.RaisePropertyChanged("TimeStamp");
       }
   }

   /// <remarks/>
   [System.Xml.Serialization.XmlIgnoreAttribute()]
   public bool TimeStampSpecified
   {
       get
       {
           return this.timeStampFieldSpecified;
       }
       set
       {
           this.timeStampFieldSpecified = value;
           this.RaisePropertyChanged("TimeStampSpecified");
       }
   }

   /// <remarks/>
   [System.Xml.Serialization.XmlAttributeAttribute()]
   public decimal Version
   {
       get
       {
           return this.versionField;
       }
       set
       {
           this.versionField = value;
           this.RaisePropertyChanged("Version");
       }
   }

   /// <remarks/>
   [System.Xml.Serialization.XmlAttributeAttribute()]
   public bool AvailRatesOnly
   {
       get
       {
           return this.availRatesOnlyField;
       }
       set
       {
           this.availRatesOnlyField = value;
           this.RaisePropertyChanged("AvailRatesOnly");
       }
   }

   /// <remarks/>
   [System.Xml.Serialization.XmlIgnoreAttribute()]
   public bool AvailRatesOnlySpecified
   {
       get
       {
           return this.availRatesOnlyFieldSpecified;
       }
       set
       {
           this.availRatesOnlyFieldSpecified = value;
           this.RaisePropertyChanged("AvailRatesOnlySpecified");
       }
   }

   public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

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

我得到的例外是

  

预计不会输入带有数据合约名称''的''。考虑使用DataContractResolver或将任何静态未知的类型添加到已知类型列表中 - 例如,使用KnownTypeAttribute属性或将它们添加到传递给DataContractSerializer的已知类型列表中。

我设法公开这些对象的唯一方法是使用[DataContract]装饰它们,使用[DataMember]装饰属性。

但是,我遇到的问题是我的reference.cs包含很多对象,我宁愿找到一种自动化的方法。

有什么建议吗?

0 个答案:

没有答案