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