自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

設(shè)置WCF服務(wù)配置信息相關(guān)經(jīng)驗分享

開發(fā) 開發(fā)工具
當(dāng)我們在用到WCF服務(wù)的時候,需要配置WCF服務(wù)配置信息,如果每次都這樣做一遍,非常浪費時間和繁瑣。那么有沒有一種動態(tài)配置WCF服務(wù)配置信息的呢?

WCF服務(wù)配置信息中有許多東西需要我們?nèi)ミM行適當(dāng)?shù)男薷幕蛘咴O(shè)置,才能實現(xiàn)一些功能。在這里我們將會了解到有關(guān)WCF服務(wù)配置信息的一些動態(tài)設(shè)置方法。#t#

在Silverlight中是使用ServiceReferences.ClientConfig文件來保存和查看WCF服務(wù)配置信息的,而ServiceReferences.ClientConfig又是包含在.xap文件中的。

這樣就導(dǎo)致如果您的Silverlight工程有用到WCF服務(wù)就需要在每次部署到不同網(wǎng)站的時候重新更改下WCF的配置并重新編譯。而且這個重新配置的過程又往往可能需要Visual Studio 2008的幫助來重新鏈接WCF服務(wù)。

而且對于有些部署的服務(wù)器就可能非常不現(xiàn)實了(有的服務(wù)器要求系統(tǒng)干凈,不允許安裝其他軟件)。

那么怎么辦呢?

WCF服務(wù)配置信息解決方案:

部署時由于WCF Service的部署地址不同,將需要我們重新索引,并編譯這個程序,非常繁瑣

你可以采用如下的動態(tài)配置的方式一舉解決這個問題:

 

 

 

刪除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")));  

 

上述就是通過動態(tài)的形式獲取得到ProductService了

修改Page.xaml.cs文件如下

 

  1. void Page_Loaded(object sender,
     RoutedEventArgs e)  
  2. {  
  3. ProductServiceClient client = 
    ServiceUtil.GetDynamicClient();
    //動態(tài)獲取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. };  

 

這樣大家就可以在不用修改的情況下非常便捷的將WCF服務(wù)配置信息部署到IIS或者Apache上了。

責(zé)任編輯:曹凱 來源: 博客園
相關(guān)推薦

2009-12-22 16:03:03

WCF異常

2009-12-22 13:48:09

引用WCF服務(wù)

2009-12-07 15:02:46

WCF學(xué)習(xí)

2009-12-22 19:26:51

WCF綁定

2010-02-22 17:58:06

WCF異步上傳

2011-05-16 09:30:30

jQueryWCF

2009-12-22 18:18:11

WCF客戶端編程

2010-02-24 11:22:04

WCF方法重載

2010-02-22 17:43:19

WCF服務(wù)啟動

2010-02-22 11:10:17

WCF獲取客戶端IP

2009-11-05 15:50:25

WCF behavio

2009-12-25 09:44:52

WPF窗口設(shè)置

2017-07-27 17:37:44

MySQL死鎖日志

2010-02-25 13:54:48

WCF安全參數(shù)

2010-02-25 13:40:17

WCF禁用安全配置

2009-12-21 16:37:41

WCF獲取服務(wù)元數(shù)據(jù)

2010-02-26 16:05:14

寄宿WCF服務(wù)

2010-02-26 14:39:27

WCF服務(wù)寄宿

2009-12-18 17:24:12

Ruby配置Mysql

2009-12-21 11:19:50

WCF配置文件
點贊
收藏

51CTO技術(shù)棧公眾號