douyousu9691 2015-06-23 06:29
浏览 31
已采纳

如何在c#中调用简单的Web服务并在文本框中显示响应?

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.                
}
  • 写回答

1条回答 默认 最新

  • douqianke7467 2015-06-23 06:33
    关注

    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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?