Hi, I am using following web service and getting following result in json format but i want combine result for different -2 services
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Text;
namespace TownGreen
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "LoginWebService" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select LoginWebService.svc or LoginWebService.svc.cs at the Solution Explorer and start debugging.
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class LoginWebService : ILoginWebService
{
public bool Login(string uname, string pwd)
{
bool bresult;
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
if (con.State == ConnectionState.Closed)
{
con.Open();
}
cmd.CommandText = "select * from UserList where UserName=@username and Password=@pwd";
cmd.Connection = con;
cmd.Parameters.Add("@username", SqlDbType.VarChar, 50).Value = uname;
cmd.Parameters.Add("@pwd", SqlDbType.VarChar, 50).Value = pwd;
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read() == true)
{
bresult = true;
}
else
{
bresult = false;
}
con.Close();
return bresult;
}
public String[] GetCategory()
{
var names = new List();
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
//SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=student;User ID=sa;Password=123");
try
{
myConnection.Open();
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection;
myCommand.CommandText = "Select CategoryName from CategoryTG order by CategoryName ";
//myCommand.Parameters.AddWithValue("@name", nameFilter);
SqlDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
names.Add(myReader["CategoryName"].ToString());
}
}
catch (Exception ex)
{
//Console.WriteLine(ex.Message);
}
finally
{
myConnection.Close();
}
return names.ToArray();
}
public String[] GetSubCategory()
{
var names = new List();
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
//SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=student;User ID=sa;Password=123");
try
{
myConnection.Open();
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection;
myCommand.CommandText = "Select CategoryName,SubCategoryName from SubCategoryTG order by CategoryName ";
//myCommand.Parameters.AddWithValue("@name", nameFilter);
SqlDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
names.Add("Category: " + myReader["CategoryName"].ToString());
names.Add("SubCategory: " + myReader["SubCategoryName"].ToString());
}
}
catch (Exception ex)
{
//Console.WriteLine(ex.Message);
}
finally
{
myConnection.Close();
}
return names.ToArray();
}
}
}
I am getting followung result from my service method Login = true
GetCategory =
[
"Eat",
"Entertainment",
"Hobbies",
"Sports"
]
GetSubCategory =
[
"Category: Eat",
"SubCategory: Pubs",
"Category: Eat",
"SubCategory: Eat out ",
"Category: Entertainment",
"SubCategory: Dance",
"Category: Hobbies",
"SubCategory: Test",
"Category: Sports",
"SubCategory: Tennis",
"Category: Sports",
"SubCategory: Golf",
"Category: Sports",
"SubCategory: Soccer"
]
But i want following result
{
"Login" "True"
"Categories" |
{
"Category" "Eat",
"Entertainment",
"Hobbies",
"Sports"
}
{"Category" "Eat"
"SubCategory"|
"Eat Out"
"Pubs"
}
{"Category" "Sports"
"SubCategory"|
"Tennis"
"Golf"
}
}
}
Raja TPosted Aug 6, 2015, 8:50 PM
bool login=Service.Login(x,y) ;//ex;true;servies return data calling login method
string GetCategory = Service.GetCategory(para);//calling category method returns data
string GetSubCategory = Service. GetSubCategory(para);// calling subcategories method returns data
if (login)
{
string results = "{\"Login\":\"" + login + "\",\"Categories\":\"" + GetCategory + "\",\"GetSubCategory\":\"" + GetSubCategory + "\"}";
}
I think its is working fine. If you facing any issues or errors please share the code and clearly explain ur question.
Raja TPosted Aug 6, 2015, 8:36 PM
Gaurav PalPosted Aug 6, 2015, 12:43 PM
Raja TPosted Aug 6, 2015, 5:19 AM
Gaurav PalPosted Aug 6, 2015, 4:32 AM
Tushar PanpaliyaPosted Aug 6, 2015, 3:14 AM