Search code examples
wcf.net-2.0wshttpbinding

Using WCF in .net 2


I've got a method of connecting and use a WCF method, which is on HTTPS and requires a username and password in .net 4. Now I need to do the same but within .Net 2 and I can't seem to get it to work. I keep on getting the below error. Can anyone help?

Error {"The underlying connection was closed: An unexpected error occurred on a receive."} Inner Exception {"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."}

.Net 4 Original Code:

            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 Code

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

Solution

  • After a long trolling over the web and testing different ways of talking to a WCF method, I have found the reason why it does not work.

    Currently the WCF is set to use wsHttpBinding and now I know that .net 2, does not support it. My work around was to change the Binding from wsHttpBinding to basicHttpBinding within the Web.config of the WCF.

    To do this and not effect anything using the WCF, I have to create a seprate Sub domain that will ref a WCF with the config that has the corrected Binding.

    "The wsHttpBinding is not compatible with the ASMX-style web references used in .NET 2.0." How to consume WCF wsHttpBinding Service in application built in 2.0?