2015-02-06 20 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?