WCF-ServiceReference Response gives ArrayOfXElement instead of the object

1k views Asked by At

I am trying to write login app.

My problem is that Service gives me ArrayOfXElement instead of an object. And I do not know how to get to this object.

Here is the code:

StartPage.xaml.cs

using (...);

namespace MyFirstProject
{
public sealed partial class StartPage : Page
{
    ServiceReference1.Service1Client MyService;

    public StartPage()
    {
        this.InitializeComponent();
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        MyService = new ServiceReference1.Service1Client();
    }

    private void btnLogin_Click(object sender, RoutedEventArgs e)
    {
        ServiceReference1.GetSinglePassCmdResponse h = MyService.GetSinglePassCmdAsync(new ServiceReference1.Pass { nickName = tBoxNick_log.Text }).Result;

Now I thought that in h I have object and I can do smth like this:

testBlock.Text = "nickname: " + h.nickname + " password: " + h.pass;
    }}}

but I got error that GetSinglePassCmdResponse does not contain a definition for 'nickname'

IService1.cs

[OperationContract]
    Pass GetSinglePassCmd(Pass Pass);

[DataContract]
public partial class Pass
{
    [DataMember]
    public string nickName { get; set; }
    [DataMember]
    public string password { get; set; }
    [DataMember]
    public Nullable<System.DateTime> lastLogDate { get; set; }

Service1.svc

 public Pass GetSinglePassCmd(Pass Pass)
    {
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }
        SqlCommand cmd = new SqlCommand("SELECT * FROM Passwords WHERE nickName=@nickName", con);
        cmd.Parameters.AddWithValue("@nickName", Passwords.nickName);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        cmd.ExecuteNonQuery();
        con.Close();
        Pass pass = new Pass();
        int i = 0;
        if (ds.Tables[0].Rows.Count > 0)
        {
            //assign dataset values to array
            pass.nickName = ds.Tables[0].Rows[i]["nickName"].ToString();
            pass.password = ds.Tables[0].Rows[i]["password"].ToString();
            pass.lastLogDate = DateTime.Parse(ds.Tables[0].Rows[i]["lastLogDate"].ToString());

        }
        else pass = null;
        return pass;
    }

And in MyFirstProject->ServiceReferences->ServiceReference1->Reference.cs->GetSinglePassCmdResponse I got

public partial class GetSinglePassCmdResponse {

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public MyFirstProject.ServiceReference1.ArrayOfXElement GetSinglePassCmdResult;

    public GetSinglePassCmdResponse() {
    }

    public GetSinglePassCmdResponse(MyFirstProject.ServiceReference1.ArrayOfXElement GetSinglePassCmdResult) {
        this.GetSinglePassCmdResult = GetSinglePassCmdResult;
    }
}

Could anyone help me please... ?

PS I have also tried this:

testBlock.Text = "nickname: " + h.GetSinglePassCmdResult.nickname + " password: " + h.GetSinglePassCmdResult.pass;
0

There are 0 answers