1
我有問題從JQuery AJAX調用WCF服務。代碼添加WCF的複雜對象?
[DataMember]
public virtual Role Role { get; set; }
後,我得到的錯誤狀態12152.如果我註釋掉[數據成員]角色的方法一切工作的屬性:除非我嘗試將此代碼添加到User類GetUserDetails工作正常。
這裏的OperationContract的的方法:
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped
)]
User GetUserDetails(string userName);
和用戶等級:
[DataContract]
[KnownType(typeof(Role))]
public class User
{
[DataMember]
public virtual int UserId { get; set; }
[DataMember]
public virtual string UserName { get; set; }
[DataMember]
public virtual string FirstName { get; set; }
[DataMember]
public virtual string LastName { get; set; }
[DataMember]
public virtual string Email { get; set; }
[DataMember]
public virtual string Company { get; set; }
[DataMember]
public virtual string Comments { get; set; }
[DataMember]
public virtual bool IsApproved { get; set; }
[DataMember]
public virtual bool IsLocked { get; set; }
[DataMember]
public virtual bool LoggedIn { get; set; }
}
角色類
[DataContract]
public class Role
{
[DataMember]
public virtual string Name { get; set; }
[DataMember]
public virtual string Description { get; set; }
}
我會感謝您的幫助!
你打開WCF診斷來獲取潛在的異常嗎? – RQDQ 2012-02-07 18:38:40
我有這個代碼在web配置: 但仍然在迴應我只得到狀態12152.請參閱截圖:[鏈接](http://ScrnSht.com/sjrgle) –
2012-02-07 23:31:08
還有更多。您可以通過執行以下操作獲取更多信息:http://msdn.microsoft.com/en-us/library/ms733025.aspx – RQDQ 2012-02-08 12:52:05