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", " ");