作爲我的WCF Web服務返回消息的一部分,我創建了三個自定義類。它們在我的返回消息類中實現,它包含一個DataContract
裝飾(很確定這是應該如何完成的)。在WCF Test Client中使用自定義類
然而,當我運行的Visual Studio 2012 WCF測試客戶端,我得到了以下錯誤消息(黑色高亮顯示)
應用程序代碼
類暴露在程序調用網絡服務。這個調用一個方法用的CloneMessage
返回類型(下面詳細說明)
namespace OKeeffeDataService
{
public class MonetToDss : IMonetToDss
{
private AgentCloneRules _agentClone;
public MonetToDss()
{
_agentClone = new AgentCloneRules();
}
[PrincipalPermission(SecurityAction.Demand, Role = "AgentPaymentUpdater")]
public CloneMessage CloneRequest(string agentId)
{
//TODO: Validate agent Id?
EventLog.WriteEntry("OKeeffe", "Made it to CloneRequest", EventLogEntryType.Information);
return _agentClone.CloneRequest(agentId);
}
}
}
應用代碼接口
namespace OKeeffeDataService
{
[ServiceContract]
public interface IMonetToDss
{
[OperationContract]
CloneMessage CloneRequest(string agentId);
}
}
克隆郵件類
這是類的WCF服務返回。 AgentClone
和RelationshipCode
類由實體框架生成並擴展爲System.Data.Objects.DataClasses.EntityObject
。 AgentAddresses
是我用標準string
屬性表示的街道,城市,州,郵編等(下面列出)編寫的自定義類。
namespace BusinessEntities
{
[DataContract]
public class CloneMessage : ICloneMessage
{
[DataMember]
public AgentClone AgentInformation { get; set; }
[DataMember]
public IList<AgentAddress> AgentAddresses { get; set; }
[DataMember]
public IList<RelationshipCode> RelationshipCodes { get; set; }
[DataMember]
public string ErrorMessage { get; set; }
public CloneMessage(){}
public CloneMessage(AgentClone agtTran, IList<AgentAddress> addresses, IList<RelationshipCode> relationshipCodes)
{
this.AgentInformation = agtTran;
this.AgentAddresses = addresses;
this.RelationshipCodes = relationshipCodes;
}
}
}
克隆消息接口
namespace BusinessEntities
{
public interface ICloneMessage
{
AgentClone AgentInformation { get; set; }
IList<AgentAddress> AgentAddresses { get; set; }
IList<RelationshipCode> RelationshipCodes { get; set; }
String ErrorMessage { get; set; }
}
}
EDIT
添加枚舉和類到後
AgentAddresses類
AddressType
是自定義枚舉。
namespace BusinessEntities
{
[DataContract]
public class AgentAddress : IAgentAddress
{
[DataMember]
public AddressTypeValues.AddressType AddressType { get; set; }
[DataMember]
public string Street1 { get; set; }
[DataMember]
public string Street2 { get; set; }
[DataMember]
public string Street3 { get; set; }
[DataMember]
public string City { get; set; }
[DataMember]
public string State { get; set; }
[DataMember]
public string ZipCode { get; set; }
}
}
AddressTypeValues枚舉
namespace BusinessEntities
{
public class AddressTypeValues
{
[DataContract(Name = "AddressType")]
public enum AddressType
{
[EnumMember(Value = "Home")]
Home,
[EnumMember(Value = "Mailing")]
Mailing,
[EnumMember(Value = "Location")]
Location,
[EnumMember(Value = "Other")]
Other
}
}
}
AgentClone和RelationshipCode類的頭
[EdmEntityTypeAttribute(NamespaceName="AgentResourcesReturn", Name="AgentClone")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class AgentClone : EntityObject
[EdmEntityTypeAttribute(NamespaceName="AgentResourcesReturn", Name="RelationshipCode")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class RelationshipCode : EntityObject
仍然得到相同的錯誤信息 – NealR
枚舉已知類型丟失..你可以添加並重試? –
已添加並且仍然沒有運氣 – NealR