我有一个返回Object-I的WCF服务。 Object-I是List,String X,List的集合。我的WCF服务运行没有任何错误并返回它但是当我在我的silverlight应用程序中调用它时,我无法读取此对象 - 我。 请帮助我
//WCF Service Interface
[ServiceContract]
public interface IUserConfiguration
{
[OperationContract]
userlistresponse GetUser();
}
[DataContract]
public class userlist
{
[DataMember]
public string UserID { get; set; }
[DataMember]
public string UserName { get; set; }
[DataMember]
public string Password { get; set; }
[DataMember]
public string User_Type { get; set; }
[DataMember]
public string Salutation { get; set; }
[DataMember]
public string First_Name { get; set; }
[DataMember]
public string Middle_Name { get; set; }
[DataMember]
public string Last_Name { get; set; }
[DataMember]
public int User_Level { get; set; }
[DataMember]
public string Address { get; set; }
[DataMember]
public string City { get; set; }
[DataMember]
public string State { get; set; }
[DataMember]
public string Pincode { get; set; }
[DataMember]
public string Landmark { get; set; }
[DataMember]
public string Landline1 { get; set; }
[DataMember]
public string Landline2 { get; set; }
[DataMember]
public string Landline3 { get; set; }
[DataMember]
public string Mobile { get; set; }
[DataMember]
public string Email { get; set; }
[DataMember]
public string Status { get; set; }
[DataMember]
public string Token { get; set; }
[DataMember]
}
[DataContract]
public class ErrorManager
{
public string Error_ID { get; set; }
public string Field { get; set; }
}
[DataContract]
public class userlistresponse
{
public List<userlist> usersdetails { get; set; }
public bool Flag { get; set; }
public List<ErrorManager> Error { get; set; }
}
//WCF Service Implementation
public userlistresponse GetUser()
{
userlistresponse ErrorUser = new userlistresponse();
try
{
DALUsersDetails DUD = new DALUsersDetails();
return DUD.GetUserDetails();
}
catch (Exception Ex)
{
ErrorUser.Error.Add(new ErrorManager {Error_ID = "SUR0000",Field = Ex.Message.ToString()});
ErrorUser.Flag = false;
}
return ErrorUser;
}
//DATA ACCESS LAYER Just Returns a List From DataBase
这里一切正常。可以在Silverlight应用程序中调用WCF服务,并且可以使用该方法。
//Silverlight Application
public Searchuser()
{
InitializeComponent();
UserConfigurationClient UserClient = new UserConfigurationClient();
UserClient.GetUserCompleted += new EventHandler<GetUserCompletedEventArgs>(UserClient_GetUserCompleted);
UserClient.GetUserAsync();
}
void UserClient_GetUserCompleted(object sender, Proto.UserReference.GetUserCompletedEventArgs e)
{
if (e.Result != null)
{
Proto.UserReference.userlistresponse user = new userlistresponse();
user = e.Result;//Its Just Returns a string.
if(user.flag == false)
//Here is the Problem- The Object User[userlistresponse] does not shows or exposes the member inside that object.
{
.......................//some code
}
}
}
答案 0 :(得分:3)
如果您对该课程使用[DataContract]
,则应为所有您不想跳过的属性添加[DataMember]
属性。