WCF新手尋求幫助。我在做什麼錯在這裏: ICardServiceWCF中的複合類型錯誤
[ServiceContract(Namespace = "http://xxxx.xxxxxx.xxxx/xx/xxxxxx")]
interface ICardService
{
[OperationContract]
Coupon CreateCouponCard(string cardDefinitionCode);
}
public class CardService : ICardService
{
public Coupon CreateCouponCard(string cardDefinitionCode)
{
Coupon composite = new Coupon();
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.PassTypeIdentifier="sdfsdf";
composite.Icon.DisplayGroup = "czxczxczx";
}
return composite;
}
}
[DataContract(Namespace = "")]
public class Coupon : CardCommonDefinition
{
[DataMember]
public string Description {get; set;}
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
}
[DataContract(Namespace = "")]
public class CardCommonDefinition
{
[DataMember]
public string PassTypeIdentifier {get; set;}
[DataMember]
public CardFieldDefinitionEntity Icon {get; set;}
}
[DataContract(Namespace = "")]
public class CardFieldDefinitionEntity
{
[DataMember]
public string DisplayGroup {get; set;}
}
當我運行它時,它在composite.Icon.DisplayGroup =「czxczxczx」;失敗。對象未設置爲對象的實例。
我沒有任何線索來解決它,你能幫我嗎?
您需要確保在設置「DisplayGroup」屬性之前初始化Coupon對象的Icon屬性。 –