Click here to Skip to main content
15,905,229 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
using MySql.Data.MySqlClient;
using System.Data;
/// <summary>
/// Summary description for loginvalidation
/// </summary>
/// 
public class customer
{
    public int id { get; set; }
    public string name { get; set; }
    public int uid { get; set; }
}
public class loginvalidation
{
    connection_class c=new connection_class();
    MySqlCommand cmd;
    MySqlDataReader dr;
    MySqlConnection con;
    [WebMethod]
    [ScriptMethod(ResponseFormat=ResponseFormat.Json)]
    public string validatelogin(string username,string password)
    {
        customer[] cus=new customer[]
        {
            new customer()
            {
                id=101,
                name="Eswar",
                uid=3473
            }
        };
        return new JavaScriptSerializer().Serialize(cus);
    }



}




My Webservice Output:

XML
<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="http://tempuri.org/">[{"id":101,"name":"Eswar","uid":3473}]</string>





Can anyone help me ??? How to get this response in my C# windows application and print into text box fields
Posted
Updated 23-Aug-15 8:42am
v2
Comments
Afzaal Ahmad Zeeshan 23-Aug-15 14:41pm    
That is a JSON within XML, as far as I can understand.

1 solution

Please follow below process:

Step1: Add service reference to Windows App.

Step2: Add reference System.Web.Extensions;

Step3: Add namespace using System.Web.Script.Serialization;

Step4: Add below code:

C#
WebService1SoapClient cc = new WebService1SoapClient();
            string test = cc.validatelogin();
            
customer[] deserialized = new JavaScriptSerializer().Deserialize<customer[]>(test);

foreach (customer customerRec in deserialized)
{
    int id = customerRec.id;
    string name = customerRec.name;
    int uid = customerRec.uid;
}


Note: Make sure that customer class is available in Windows project also because it is required when we do deserializeation.
 
Share this answer
 
Comments
Eswar1988 24-Aug-15 11:23am    
Thank you..

Is working well

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900