2015-02-06 53 views
3

我有連接的方法和使用WCF方法,這是對HTTPS,需要在.NET中的用戶名和密碼4. 現在我需要做相同的,但內淨2,我似乎無法讓它工作。我繼續得到下面的錯誤。誰能幫忙?在.NET中使用WCF 2

錯誤 {「基礎連接已關閉:在接收時發生意外錯誤」} 內部異常 {「無法讀取從傳輸連接數據:一個現有的連接被強制由遠程關閉主機「}

的.Net 4原始代碼:

  WSHttpBinding myBinding = new WSHttpBinding(); 
      myBinding.Security.Mode = SecurityMode.Transport; 
      myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; 
      EndpointAddress ea = new EndpointAddress(wcfURL); 
      var web = new Gateway.GatewayClient(myBinding, ea); 
      // var web = new Gateway.GatewayClient(); 
      XMLCrypto crypto = new XMLCrypto(); 


      web.ClientCredentials.UserName.UserName = crypto.DecryptString(username); 
      web.ClientCredentials.UserName.Password = crypto.DecryptString(password); 
      web.Open(); 
      web.Inbound("HOLog", message.Trim().Replace("\n", "").Replace(@"\\", "")); 
      web.Close(); 

的.Net 2代碼

XMLCrypto crypto = new XMLCrypto(); 
      url = "http://..../gateway/gateway.svc"; 
      userName = crypto.DecryptString(userName); 
      password = crypto.DecryptString(password); 

      var web = new Gateway.Gateway(); 
      var credentials = new NetworkCredential(userName, password); 
      CredentialCache credentialCache = new CredentialCache(); 
      credentialCache.Add(new Uri(url), "Basic", credentials); 

      web.Credentials = credentials; 

      string returnMessage = web.Inbound("LSOA", " "); 

回答

1

長曳通過網絡和測試跟一個WCF方法的不同方式後,我發現,爲什麼它不工作的原因。

目前WCF設置爲使用的wsHttpBinding,現在我知道,.NET 2,不支持它。我的工作是在WCF的Web.config中將綁定從wsHttpBinding更改爲basicHttpBinding。

要做到這一點,並使用WCF不會影響任何東西,我要創建將REF一個WCF與具有校正綁定配置一個seprate子域。

「的的wsHttpBinding是不是在使用.NET 2.0的ASMX樣式的Web引用兼容。」 How to consume WCF wsHttpBinding Service in application built in 2.0?