您的位置:首页 > 其它

Silverlight 中WCF 服务调用方法

2012-08-24 14:02 351 查看
WCF Serives 的调用。通常我们是通过在项目中添加Services references 来调用的。

现在我来介绍另一种调用方式。英文资料很多。但是中文资料目前没看到过。

第一步:准备工作

新建一个silverlight Application。并且在silverlight 项目中添加一个wcf service 叫做 Service1 包括两个文件

IService1.cs和Service1.svc

并在其中添加一个方法HelloAction

调用

EndpointAddress endpointAddress = new EndpointAddress(uri);
IService1 s = new ChannelFactory<IService1>(new BasicHttpBinding(), endpointAddress).CreateChannel();
s.BeginHelloAction(callback =>
{
string result = s.EndHelloAction(callback);
//Deployment.Current.Dispatcher.BeginInvoke(() =>
//{
//    textBox1.Text = result;
//});

}, null);


源代码下载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: