You must Sign In to post a response.
  • Category: Webservices

    Webservice return string


    I have datatable contains 5 columns and 10 rows. I want how to write asmx webservice to return a string.

    Could anybody guide to me.

    Thanks and regards
  • #763132
    The below logic should be your webservice

    public class empService : System.Web.Services.WebService
    public String getEmp(int id)
    //some logic

    The below logic should be your client application

    public partial class _Default : System.Web.UI.Page
    protected void Button1_Click(object sender, EventArgs e)
    localhost.empService obj=new localhost.empService();
    String output=obj.getEmp(int.Parse(TextBox1.Text));

    Refer the below article of creating and consuming webservice using an example with source code.

    Sridhar Thota.
    Editor: DNS Forum.

  • #763144

    not only in webserivce in any case if you want to return string result then your type should be "string".

    Refer below sample for your reference,

    public string methodname()
    return "Hi";

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #763387
    You can do this in many ways.

    1. Create public List

    Create new public class having the 5 columns and assign the values into it as list. While accessing the webservice fill this list and get this as one of the output in your webservice

    2. You can go for restfull web service with JSON output.

    By Nathan
    Direction is important than speed

Sign In to post your comments