2011-03-11 29 views
1

當我做到這一點,在這樣的在運行時更改服務的地址

<client> 
     <endpoint address="http://192.168.1.7/zfsapi/api.php" binding="basicHttpBinding" 
      bindingConfiguration="ZfsSoapBinding" contract="SourceAPI.ZfsSoapPort" 
      name="ZfsSoapPort" />   
    </client> 

而且我在運行時這樣

 EndpointAddress epa1 = new EndpointAddress("http://192.168.1.7/zfsapi/api.php"); 
     DemoChangingAddressApi.SourceAPI.ZfsSoapPortClient oservice = new SourceAPI.ZfsSoapPortClient(binding1, epa1); 
     DemoChangingAddressApi.SourceAPI.ZfsVolume[] v1 = oservice.getVolumeList(); 


     // or instantiate whatever other binding you're using  
     BasicHttpBinding binding = new BasicHttpBinding(); 

     // define the endpoint address 
     EndpointAddress epa = new EndpointAddress("http://192.168.1.8/zfsapi/api.php"); 

     // create your WCF client-side proxy based on those settings 
     DemoChangingAddressApi.SourceAPI.ZfsSoapPortClient oservice1 = new SourceAPI.ZfsSoapPortClient(binding, epa); 
     DemoChangingAddressApi.SourceAPI.ZfsVolume[] v2 = oservice1.getVolumeList(); 

chnages我的地址的客戶端,我的Web配置我得到錯誤@DemoChangingAddressApi.SourceAPI.ZfsVolume[] v2 = oservice1.getVolumeList();

錯誤:

反序列化操作'getVolumeList'的消息體 錯誤。

我怎麼可以,如果你訪問的web.config文件的XML,你總是能夠在運行時在提供服務

+0

如果第一次調用(v1)工作,第二次調用不成功,則問題出現在第二臺服務器上。配置不同或者服務的操作不提供相同的結果,並且客戶端無法反序列化響應。 – 2011-03-11 20:30:43

回答

0

運行時修改地址: 事情是這樣的: //下面的代碼中我有動態複製網站的要求

 // Set the root path of the Web application that contains the 
     // Web.config file that you want to access. 
     string configPath = ConfigurationManager.AppSettings["appRoot"] + virtualDirectoryName + "\\"; 

     XmlDocument doc = new XmlDocument(); 
     bool change = false; 
     string configFile = Path.Combine(configPath, "web.config"); 
     doc.Load(configFile); 

     //get root element 
     System.Xml.XmlElement Root = doc.DocumentElement; 
     //I have created appSettings dictionary that holds key/value pairs that wanted to update in section. 
     Dictionary<string, object> appSettings = new Dictionary<string, object>(); 
     appSettings.Add("connString", "server=" + serverAddressAppDb + 
          "; uid=" + uidAppDb + "; pwd=" + pwdAppDb + 
          "; database=" + virtualDirectoryName + "; min pool size=1; max pool size=100;"); 
     appSettings.Add("applogin", urlApp + virtualDirectoryName + "/login.aspx"); 
     appSettings.Add("appUrl", urlApp + virtualDirectoryName); 
     appSettings.Add("mailer_completeImagePath", urlApp + virtualDirectoryName + "/backgrounds/"); 
     appSettings.Add("mailer_pathImagesComplete", urlApp + virtualDirectoryName + "/images/"); 

     // Now the code below will go loop through each key/value pair under section and will compare the values in with appSettings dictionary. If it sees values are different, It will update in section. 
     XmlNode appNode = Root["appSettings"]; 
     foreach (XmlNode node in appNode.ChildNodes) 
     { 
      if (node.Attributes != null) 
      { 
       try 
       { 
        string key = node.Attributes.GetNamedItem("key").Value; 
        string value = node.Attributes.GetNamedItem("value").Value; 
        if (appSettings.ContainsKey(key) && value != appSettings[key].ToString()) 
        { 
         node.Attributes.GetNamedItem("value").Value = appSettings[key].ToString(); 
         change = true; 
        } 
       } 
       catch (Exception e) 
       { 
       } 
      } 
     } 
相關問題