简体   繁体   中英

How to call simple web-service in c# and show response in text-box?

Today is my first day at c#. I want to call simple web-service from c# desktop application. I searched over net but could not found any simple example in this regard. Can anyone please help me to start this job from ABC. I have web-service as echo.php( placed in htdocs folder of xampp)

<?php
    echo "Hello";    
?>

and want to call it on button press

private void button1_Click(object sender, EventArgs e)
{
    //   want to call web-service from here and want to print response in   
    //   any text box.                
}

There are numerous methods to do this in C#, For your simple example, a WebClient -Call should do what you want.

private void button1_Click(object sender, EventArgs e)
{
    var client = new WebClient();
    var response = client.DownloadString("http://localhost:8000"); // or whatever your url might look like

    myTextBox.Text = response;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM