In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to call WEB Service API in C # Winform. I hope you will get something after reading this article. Let's discuss it together.
After building a very simple WEB Service, let's take C # WinForm to call WEB Service API as an example to talk about how to use it. In the service, we only have one automatic generation method: HelloWord (), which is implemented as follows:
[WebMethod] public string HelloWorld () {return "HelloWorld";}
In the process of Winform calling WEB Service API, we add a button with Winform, add a click event, and pop up a dialog box in the event handler to display the result of HelloWord.
1. Add WEB reference
Create a new Windows application project in VS2005, name it testwebservice, add a WEB reference to the project, right-click on the project name of solution Explorer, enter the path of the WEB server in the URL input box in the pop-up dialog box: such as http:// your domain name / web service service path / service.asmx, search for this service after clicking the "forward" button, and report the service found on the right And display the service.asmx page on the left, we enter a name in the WEB reference name input box, which will be the namespace name of the WEB service in the program, here we name it mywebservice.
two。 Add button click event
Drag a Button button in Form and double-click the event handling method as follows:
Private void button1_Click (object sender, EventArgs e) {mywebservice.Service ws = new testwebservice.mywebservice.Service (); MessageBox.Show (ws.HelloWorld ();}
Where mywebservice.Service ws = new testwebservice.mywebservice.Service () instantiates a WEB service object, and ws.HelloWorld () invokes the HelloWorld method in the WEB service, whose return string is displayed with the MessageBox.Show () function.
Well, the simplest WinForm example of invoking the WEB service API has been completed. Compile and run, click the button, and the dialog box will pop up with the message "Hello World".
Importantly, in the. Net WEB service API, in addition to general data types, you can also return structures and DataSet objects, with this, you can build most of our database applications.
Well, the next job is to add your Winform to the WEB service and call WEB Service API to finish your work.
After reading this article, I believe you have a certain understanding of "how to call WEB Service API in C # Winform". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.