我正在编写WCF服务, ExtensionDataObject 显示在服务参考的 Reference.cs 文件中,即使我没有它在我的数据类中定义。
我知道ExtensionDataObject的用途,但不想使用它。
我不知道为什么会出现 ... 有人可以告诉我如何不将它包含在我的服务参考中吗?此外,还有一个OptionalFieldAttribute,在我的服务引用中声明,它再次不是我的数据类的一部分。我怎么能删除它?
以下是我客户端上生成的服务引用声明:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="User", Namespace="http://www.Ryder.com/SOA/DataContracts/2014/02/17")]
[System.SerializableAttribute()]
public partial class User : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string PasswordField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Ryder.ShopProcessService.Outbound.ShopProcessService.Permissions PermissionsField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string UserIDField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Ryder.ShopProcessService.Outbound.ShopProcessService.UserTypeEnum UserTypeField;
[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string Password {
get {
return this.PasswordField;
}
set {
if ((object.ReferenceEquals(this.PasswordField, value) != true)) {
this.PasswordField = value;
this.RaisePropertyChanged("Password");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Ryder.ShopProcessService.Outbound.ShopProcessService.Permissions Permissions {
get {
return this.PermissionsField;
}
set {
if ((object.ReferenceEquals(this.PermissionsField, value) != true)) {
this.PermissionsField = value;
this.RaisePropertyChanged("Permissions");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string UserID {
get {
return this.UserIDField;
}
set {
if ((object.ReferenceEquals(this.UserIDField, value) != true)) {
this.UserIDField = value;
this.RaisePropertyChanged("UserID");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Ryder.ShopProcessService.Outbound.ShopProcessService.UserTypeEnum UserType {
get {
return this.UserTypeField;
}
set {
if ((this.UserTypeField.Equals(value) != true)) {
this.UserTypeField = value;
this.RaisePropertyChanged("UserType");
}
}
}
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));
}
}
}
这是我的服务项目中相应的类声明:请注意,我刚刚将名称空间更改为“abc”以保护隐私......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.ServiceModel;
namespace abc.Enterprise.DataTransferObjects
{
[Serializable, DataContract(Name = "User", Namespace = "http://www.abc.com/SOA/DataContracts/2014/02/17")]
public class User
{
private UserTypeEnum userType;
private string userID;
private string password;
private Permissions permissions;
public User()
{
}
[DataMember(Name = "UserType")]
public UserTypeEnum UserType
{
get
{
return userType;
}
set
{
userType = value;
}
}
[DataMember(Name = "UserID")]
public string UserID
{
get
{
return userID;
}
set
{
userID = value;
}
}
[DataMember(Name = "Password")]
public string Password
{
get
{
return password;
}
set
{
password = value;
}
}
[DataMember(Name = "Permissions")]
public Permissions Permissions
{
get
{
return permissions;
}
set
{
permissions = value;
}
}
}
}