Obtain and read weather forecasts using Web Service

Source: Internet
Author: User
Tags sapi

Environment: Visual Studio 2010 C #1. Create a project --> Windows Forms Application. Enter the solution name, which is assumed to be TTS. 2. Design a textBox and a Button on the interface. TextBox1 is used to hold text information. Click button1 to trigger the event to obtain the weather forecast and read it aloud. 3. In Solution Explorer, right-click solution TTS and choose add service reference. The following page is displayed:

Click "advanced" and the following page is displayed:

Click Add Web reference to bring up the following interface: Enter http://www.webxml.com.cn/WebServices/WeatherWebService.asmx in the address bar

-------------------------------------- Split line start ------------------------------------------------------ [digress] This is a Web Service for weather forecasts provided by China. On the homepage of the site. In addition, I would like to introduce several overseas Web Service sites (I have never tried it, but I don't know if it can be used): · Web services dedicated to map: websites? Sort = category -------------------------------------- split line end ------------------------------------------------ NOTE 1: The title of the current window is "add Web reference. The first step is "add service reference ". These two types are different. Even if you enter the above address in the address bar in step 1, you can also find this Web service. However, after adding the address to the project, there will be problems when using it later, the required classes and methods cannot be found (For details, refer to the code below ). Or maybe I won't use "service reference ". In short, I only know how to use "Web reference ". NOTE 2: Pay attention to the "Web reference name", which is equivalent to the namespace of the added Web reference. You can change it by yourself. Click "add reference". The Web Service of this weather forecast is added to our project. You can see it in "solution Resource Manager,

4. The next step is how to use weather web service. Add the response function button1_Click for button1. For details, see the code:

   button1_Click(     city = = [] wwsArray =.textBox1.Text = wwsArray[] +   + wwsArray[] +   + wwsArray[+   + wwsArray[] +  ++  + wwsArray[]  + + Environment.NewLine + wwsArray[
The information obtained from the Web Service is put in the string array wwsArray []. I have selected some strings and put them in textBox1. wwsArray [0] indicates "Hubei ", wwsArray [1] indicates "Wuhan ". You can also put the entire string array into textBox1, but note that some information is the image name of the city, as if wwsArray [2] is. 5. added the function of reading weather forecasts. First, search for sapi. dll under drive C. My example has this dll under both directories:

Remember the directory of this file. You can use the directory. The two files are the same. In Visual Studio 2010, right-click the project name TTS in Solution Explorer and choose --> Add reference. The following figure is displayed: on the browsing tab, select the sapi we found in drive C. dll, click OK. And then add it. You can see in the project that this product is called "SpeechLib ". 6. Use the SpeechLib library in the code. The complete code is as follows:
    button1_Click(            ==  (.textBox1.Text.Trim() ==                      city = = [] wwsArray =.textBox1.Text = wwsArray[] +   + wwsArray[] +   + wwsArray[] +   + wwsArray[] +  ++  + wwsArray[]  + + Environment.NewLine + wwsArray[

 

Generation running effect:

When text information appears, a female voice can be heard while reading aloud. It is intelligent to cut sentences and words.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.