Team Fly |
Page 325
If you look at the service description, you see the necessary data types and parameters required: ReverseWords(s As string) As string. This is the right service, so click the Add Reference button. Look in Solution Explorer to see that your reference has been added.
This reference is similar to the simulation of Internet connections that is used to test ASP.NET projects and Web services (as in the previous example). The local host refers to your local machine pretending to be an Internet URL.
Now write the code that consumes a Web service by feeding a parameter to it, then receiving the response and displaying the result in the TextBox.
Type in the source code shown in Listing 13.2.
LISTING 13.2: CONSUMING A WEB SERVICE |
Private Sub Form1_Load(ByVal sender As System.Object, _ |
Press F5 to instantiate a new Service1, then invoke it and pass a parameter. If you have a firewall, it will probably ask if you want to permit your VB.NET project to "contact the Internet," or it may ask your permission to let this service connect to local host port 80. You get back from the Web service this response: sentence my is This.
TIP If you edit a Web service, be sure to right-click localhost in the Solution Explorer, then choose Update Web Reference in the context menu to rebuild the service.
Like many other Internet communications, Web services are theoretically stateless. Parameters are passed to the service, but that data is only persisted in memory while the service is generating a response. After the response is sent, the parameters are discarded. Normally, details like a client's fax number are not retained by the server. Statelessness is often necessary—you usually don't have room nor reason to store the number of every visitor to your popular website.
Some Web services don't need to retain data about the client. There's no need to retain their zip code after sending a client the local weather report, for instance. But what if you do want to retain data about certain returning visitors, such as customers, so they don't have to repeatedly supply you with their fax number every time they place an order?
Team Fly |