下面是服务的部分代码:
代码如下 |
复制代码 |
///
/// Summary description for WeatherWebService
///
[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
{
///
/// 获取第三方ws支持的指定省份下的城市名称
///
///
///
[WebMethod]
public string[] GetSupportCity(string provinceName)
{
var service = new WS.WeatherWebServiceSoapClient();
return service.getSupportCity(provinceName);
}
}
|
Step2:在SL项目中引用本地服务
直接添加本地的WebService引用,然后在程序中调用,下面是部分代码:
代码如下 |
复制代码 |
private void button1_Click(object sender, RoutedEventArgs e)
{
var service = new LocalServiceReference.WeatherWebServiceSoapClient();
service.GetSupportCityCompleted+=new EventHandler(service_GetSupportCityCompleted);
service.GetSupportCityAsync("安徽");
}
void service_GetSupportCityCompleted(object sender, GetSupportCityCompletedEventArgs e)
{
this.ListContent.ItemsSource = e.Result;
}Step3:查看结果
|
先看直接访问第三方服务的截图:
这是使用本地服务作为中介的结果: