Silverlight专题(16)- 动态设置WCF Service配置信息
2009-02-28 11:56:14 来源:WEB开发网部署时由于WCF Service的部署地址不同,将需要我们重新索引,并编译这个程序,非常繁琐
你可以采用如下的动态配置的方式一举解决这个问题:
删除ServiceReferences.ClientConfig文件,并在Silverlight 工程下添加一个类文件(Class File)ServiceUtil.cs如下
1: public static ProductServiceClient GetDynamicClient()
2: {
3: BasicHttpBinding binding = new BasicHttpBinding(
4: Application.Current.Host.Source.Scheme.Equals("https", StringComparison.InvariantCultureIgnoreCase)
5: ? BasicHttpSecurityMode.Transport : BasicHttpSecurityMode.None);
6: binding.MaxReceivedMessageSize = int.MaxValue;
7: binding.MaxBufferSize = int.MaxValue;
8: return new ProductServiceClient(binding, new EndpointAddress(
9: new Uri(Application.Current.Host.Source, "../ProductService.svc")));
10: }
上述就是通过动态的形式获取得到ProductService了
修改Page.xaml.cs文件如下
1: void Page_Loaded(object sender, RoutedEventArgs e)
2: {
3: ProductServiceClient client = ServiceUtil.GetDynamicClient();//动态获取ProductServiceClient
4: this.Cursor = Cursors.Hand;
5: client.RetreiveDataAsync();
6: client.RetreiveDataCompleted += (sender2, e2) =>
7: {
8: if (e2.Cancelled == false && e2.Error == null)
9: {
10: ObservableCollection<ProductInfo> products = e2.Result;
11: this.ProductLBCtl.ItemsSource = products;
12: this.Cursor = Cursors.Arrow;
13: }
14: };
15: }
Tags:Silverlight 专题 动态
编辑录入:爽爽 [复制链接] [打 印]- ››Silverlight for Windows Phone 7开发系列(1):...
- ››Silverlight for Windows Phone 7开发系列(2):...
- ››Silverlight for Windows Phone 7开发系列(3):...
- ››Silverlight for Windows Phone 7开发系列(4):...
- ››动态调用对象事件
- ››动态创建控件支持事件响应并可保存与读取
- ››Silverlight for Symbian
- ››动态截获并显示窗口DC
- ››动态改变 Android 控件大小
- ››动态分区迁移主要准备过程及典型问题分析
- ››动态更改 Android 的屏幕方向
- ››专题功能优化 for V7.5 SP3 优化包
更多精彩
赞助商链接