gpt4 book ai didi

silverlight - 如何在 WCF Web 服务中返回一个对象?

转载 作者:行者123 更新时间:2023-12-04 06:27:18 25 4
gpt4 key购买 nike

我有一个返回 Object-I 的 WCF 服务。 Object-I 是 List,String X,List 的集合。我的 WCF 服务运行没有任何错误并返回它,但是当我在我的 Silverlight 应用程序中调用它时,我无法读取这个对象-I。
请帮我

//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

这里一切正常。WCF 服务可以在 Silverlight 应用程序中调用并可以使用该方法。
//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
}


}
}

User does not shows or exposes the member in userlistresponse object

最佳答案

如果您使用 [DataContract]对于类(class),您应该包括 [DataMember]您不想跳过的所有属性的属性将被转移。

关于silverlight - 如何在 WCF Web 服务中返回一个对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5893040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com