Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to make a HTTP request using c# to asmx web-method which is returning Context.Response.Write?

$
0
0

I created a web method in asmx web services and it is returning pure JSON using Context.Resopnse.Write.

Now the above line will write json data to the connection pipeline of the request but how to accept the response from c# function which is acting as a client to the web-service.

Here is my web-service method:

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void GetAllEmployeesFromEmpInPureJSON()
{
    SqlConnection vConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);
    vConn.Open();
    String vQuery = "Select * from Employee";
    SqlDataAdapter vAdap = new SqlDataAdapter(vQuery, vConn);
    DataSet vDs = new DataSet();
    vAdap.Fill(vDs, "Employee");
    vConn.Close();
    DataTable vDt = vDs.Tables[0];
    Context.Response.Write(JsonConvert.SerializeObject(vDt));
}

Here is the client function:

protectedvoidButton1_Click(object sender,EventArgs e){Lab25WebServiceSoapClient obj =newLab25WebServiceSoapClient();DataTable vDt =newDataTable();//String jsonstring = obj.GetAllEmployeesFromEmpInPureJSON();//vDt = JsonConvert.DeserializeObject(jsonstring) as DataTable;GridView1.DataSource= vDt;GridView1.DataBind();}

Here the below two lines don't work because it is a void type return method and below code will work when I am returning string instead of using context.

String jsonstring = obj.GetAllEmployeesFromEmpInPureJSON();
vDt =JsonConvert.DeserializeObject(jsonstring)asDataTable;

I think there should be something like:

String jsonstring =Context.Request(obj.GetAllEmployeesFromEmpInPureJSON())

Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>