The specific steps are not too detailed. They are nothing more than adding a new WebService file, adding Web references, generating proxy classes, defining methods, and encapsulating third-party services. I am using a weather forecast service.
The following is part of the service code:
The Code is as follows: |
Copy code |
/// <Summary> /// Summary description for WeatherWebService /// </Summary> [WebService (Namespace = "http://tempuri.org/")] [WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)] [System. ComponentModel. ToolboxItem (false)] // To allow this Web Service to be called from script, using ASP. net ajax, uncomment the following line. // [System. Web. Script. Services. ScriptService] Public class WeatherWebService: System. Web. Services. WebService { /// <Summary> /// Obtain the name of a city in a specified province supported by the third-party ws /// </Summary> /// <Param name = "provinceName"> </param> /// <Returns> </returns> [WebMethod] Public string [] GetSupportCity (string provinceName) { Var service = new WS. WeatherWebServiceSoapClient (); Return service. getSupportCity (provinceName ); } } |
Step 2: reference the local service in the SL Project
Directly add a local WebService reference and call it in the program. The following is some code:
The Code is as follows: |
Copy code |
Private void button#click (object sender, RoutedEventArgs e) { Var service = new LocalServiceReference. WeatherWebServiceSoapClient (); Service. GetSupportCityCompleted + = new EventHandler <GetSupportCityCompletedEventArgs> (service_GetSupportCityCompleted ); Service. GetSupportCityAsync ("Anhui "); } Void service_GetSupportCityCompleted (object sender, GetSupportCityCompletedEventArgs e) { This. ListContent. ItemsSource = e. Result; } Step 3: view the result |
First, directly access third-party services:
This is the result of using the local service as an intermediary: