我有一个 WCF 服务,它包含它的接口、类定义和一些其他对象类。它编译得很好,但是当我运行它时,我得到:
Type 'sarus.division.warehouse.cmms.infrastructure.data.logic.location.type.Type' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.
我的sarus.division.warehouse.cmms.infrastructure.data.logic.location.type.Type
班级也有一个属性[Serializable]
。但无论我做了什么,我都无法成功。
我怎样才能完成将此类设置为可序列化?有没有办法实现这个?
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Web;
namespace sarus.division.warehouse.cmms.proxy.services.location.type
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IType" in both code and config file together.
[ServiceContract]
public interface IType
{
[OperationContract]
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/Delete?id={id}")]
CompositeType Select(Guid id);
[OperationContract]
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
[ServiceKnownType(typeof(CompositeType))]
CompositeType List();
[OperationContract]
[WebInvoke(Method = "PUT", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
void Add(sarus.division.warehouse.cmms.infrastructure.data.logic.location.type.Type type);
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
void Update(sarus.division.warehouse.cmms.infrastructure.data.logic.location.type.Type type);
[OperationContract]
[WebInvoke(Method = "DELETE", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
void Delete(Guid id);
}
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Type" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select Type.svc or Type.svc.cs at the Solution Explorer and start debugging.
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Type : IType
{
public CompositeType Select(Guid id)
{
return new CompositeType().Select(id);
}
public CompositeType List()
{
return new CompositeType().List();
}
public void Add(sarus.division.warehouse.cmms.infrastructure.data.logic.location.type.Type type)
{
}
public void Update(sarus.division.warehouse.cmms.infrastructure.data.logic.location.type.Type type)
{
}
public void Delete(Guid id)
{
}
}
[DataContract]
[Serializable]
public class CompositeType
{
[DataMember]
public TypeColumns Columns { get; set; }
[DataMember]
public TypeData Data { get; set; }
public CompositeType()
{
Columns = new TypeColumns();
Data = new TypeData();
}
public CompositeType Select(Guid id)
{
try
{
var composite = new CompositeType();
var columns = ((HttpContext.Current.Session["PRINCIPAL"] as sarus.division.common.localization.data.principal.intelligence.Intelligence).Hubs["warehouse.cmms"].Hive["LOCATION-TYPE"] as sarus.division.common.localization.data.hive.drone.Drone).GetColumns();
foreach (var column in columns) { composite.Columns.Add(column); }
var data = new sarus.division.warehouse.cmms.infrastructure.data.logic.location.type.Type().Select(id);
composite.Data.Add(data);
return composite;
}
catch (Exception) { throw; }
}
public CompositeType List()
{
try
{
var composite = new CompositeType();
var columns = ((HttpContext.Current.Session["PRINCIPAL"] as sarus.division.common.localization.data.principal.intelligence.Intelligence).Hubs["warehouse.cmms"].Hive["LOCATION-TYPE"] as sarus.division.common.localization.data.hive.drone.Drone).GetColumns();
foreach (var column in columns) { composite.Columns.Add(column); }
var list = sarus.division.warehouse.cmms.infrastructure.data.logic.location.type.Type.List();
foreach (var data in list) { composite.Data.Add(data); }
return composite;
}
catch (Exception) { throw; }
}
}
[CollectionDataContract(Name = "GridViewColumn{0}List", ItemName = "GridViewColumn")]
public class TypeColumns : List<sarus.division.common.infrastructure.data.foundation.definitions.GridViewColumn>
{
public TypeColumns()
: base()
{
}
public TypeColumns(sarus.division.common.infrastructure.data.foundation.definitions.GridViewColumn[] items)
: base()
{
foreach (sarus.division.common.infrastructure.data.foundation.definitions.GridViewColumn item in items)
{
Add(item);
}
}
}
[CollectionDataContract(Name = "Type{0}List", ItemName = "Type")]
public class TypeData : List<infrastructure.data.logic.location.type.Type>
{
public TypeData()
: base()
{
}
public TypeData(infrastructure.data.logic.location.type.Type[] items)
: base()
{
foreach (infrastructure.data.logic.location.type.Type item in items)
{
Add(item);
}
}
}
}
编辑:这里是“sarus.division.warehouse.cmms.infrastructure.data.logic.location.type.Type”类;
using sarus.division.common.infrastructure.data.foundation.definitions;
using sarus.division.common.infrastructure.data.logic.user;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
namespace sarus.division.warehouse.cmms.infrastructure.data.logic.location.type
{
public class Type : actual.Actual
{
public List<location.Location> Locations { get; set; }
public Type(bool autoLoadDetails = false)
{
}
public Type Select(Guid id)
{
}
public List<Type> Select()
{
}
public static List<Type> List()
{
}
public void Save()
{
}
public void Delete()
{
}
}
}