Silverlight调用Web Service的方法
2010-07-01 10:10
197 查看
先展示一下我的Silverlight项目
大气象
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace HCLoad
{
public partial class uc_WebService : UserControl
{
//创建Web Service对象
ServiceReference1.WebService1SoapClient ws = new HCLoad.ServiceReference1.WebService1SoapClient();
public uc_WebService()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
AddEvent();
Bind();
}
//注册事件,有点类似Ajax的回调
private void AddEvent()
{
ws.HelloWorldCompleted += new EventHandler<ServiceReference1.HelloWorldCompletedEventArgs>(ws_HelloWorldCompleted);
ws.HelloWorld1Completed += new EventHandler<ServiceReference1.HelloWorld1CompletedEventArgs>(ws_HelloWorld1Completed);
}
//回调函数
void ws_HelloWorldCompleted(object sender, ServiceReference1.HelloWorldCompletedEventArgs e)
{
tbWeb.Text += e.Result + " hi";
}
void ws_HelloWorld1Completed(object sender, ServiceReference1.HelloWorld1CompletedEventArgs e)
{
tbWeb.Text += e.Result + " hi";
}
private void Bind()
{
ws.HelloWorldAsync();
ws.HelloWorld1Async("输入");//调用带输入参数的Web Service方法
}
}
}
一些小技巧:
1.右击Silverlight项目,添加服务引用,点发现,可以找到你创建的Web Service
2.当你修改了Web Service要重新生成一下,并且右击Silverlight的引用更新服务。
3.修改web serivce端口与你web项目端口一致,否则会提示跨域操作。
在本机上调试asp.net程序时,设置端口。
右击项目->属性->Web->使用 Visual Studio 开发服务器(D) 把自动分配端口,修改为特定端口,输入指定的端口。
大气象
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace HCLoad
{
public partial class uc_WebService : UserControl
{
//创建Web Service对象
ServiceReference1.WebService1SoapClient ws = new HCLoad.ServiceReference1.WebService1SoapClient();
public uc_WebService()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
AddEvent();
Bind();
}
//注册事件,有点类似Ajax的回调
private void AddEvent()
{
ws.HelloWorldCompleted += new EventHandler<ServiceReference1.HelloWorldCompletedEventArgs>(ws_HelloWorldCompleted);
ws.HelloWorld1Completed += new EventHandler<ServiceReference1.HelloWorld1CompletedEventArgs>(ws_HelloWorld1Completed);
}
//回调函数
void ws_HelloWorldCompleted(object sender, ServiceReference1.HelloWorldCompletedEventArgs e)
{
tbWeb.Text += e.Result + " hi";
}
void ws_HelloWorld1Completed(object sender, ServiceReference1.HelloWorld1CompletedEventArgs e)
{
tbWeb.Text += e.Result + " hi";
}
private void Bind()
{
ws.HelloWorldAsync();
ws.HelloWorld1Async("输入");//调用带输入参数的Web Service方法
}
}
}
一些小技巧:
1.右击Silverlight项目,添加服务引用,点发现,可以找到你创建的Web Service
2.当你修改了Web Service要重新生成一下,并且右击Silverlight的引用更新服务。
3.修改web serivce端口与你web项目端口一致,否则会提示跨域操作。
在本机上调试asp.net程序时,设置端口。
右击项目->属性->Web->使用 Visual Studio 开发服务器(D) 把自动分配端口,修改为特定端口,输入指定的端口。
相关文章推荐
- asp.net调用远程Web Service的二种方法
- Silverlight动态调用WEBSERVICE,WCF方法
- silverlight调用HTML中定义的JS方法
- Silverlight调用的JS方法返回对象数组的处理方法
- 分享 tsc 条码打印机 打印控件 调用方法 , c# silverlight
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(6):服务器端和客户端数据类型的自动转换:复杂类型
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(6):服务器端和客户端数据类型的自动转换:复杂类型
- VC++调用Web Service的方法及注意事项
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(3):保持用户上下文
- silverlight 进行本地串口调用的一种可行的解决方法
- ASP.NET AJAX异步调用Web Service和页面中的类方法< 收藏>
- 通过Xfire开发web service接口和客户端调用web service接口接口方法
- Silverlight的组合键、快捷键(热键)调用方法
- Silverlight中调用ClientBin下非xap内的xml的方法
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(9):服务器端和客户端数据类型的自动转换:DataTable和DataSet
- NET应用程序中异步调用Web Service的几种方法
- 使用Sharepoint的Lists Web Service调用UpdateListItems方法"增/删/改"List Items
- vs2005中web service的调用方法
- asp.net调用远程Web Service的二种方法
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法