The HTTP request is unauthorized with client authentication scheme ‘Basic’. The authentication header received from the server was ‘Basic realm=”SAP HANA Cloud Platform”‘.

In my line of work I quite often find myself connecting to Web Services to consume data, usually by SOAP or RESTful based services. They both have the good and bad points, the good points are that SOAP based exchanges usually come with a nice description of the contracts in the form of a WSDL file. However anything .net can be quite picky about how it digests these end points while a malformed or in-complete wsdl will quite happily be used by SoapUI or similar test suite, .net will struggle. Case in point if your bindings aren’t setup correctly, if you are not sure about the non-clemanture of WSDL files I suggest this as an old but good article to get you started.

I was getting the above error because I was not declaring my bindings properly, they weren’t mentioned at all in the WSDL so I suppose Visual Studio was behaving as expected, if they were they would have probably been declared in the app.config, I don’t like doing it there if I can help it though and prefer to do it programmatically. So, what I had to do was create bindings and past them with the configuration…..Something like this:

                Uri Address = new Uri("");
                EndpointAddress EndPointAddr = new EndpointAddress(Address);
                //Create your binding this normally Basic for SOAP
                BasicHttpBinding Binding = new BasicHttpBinding();
                //If you have authenticate with HTTPS with username password we need to set Transport and Message Credential
                Binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
                Binding.Security.Mode = BasicHttpSecurityMode.Transport;
                Binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
                //Instantiate Client with our binding and URI
                autoCreatedProxyClassClient ProxyClient = new autoCreatedProxyClassClient(Binding, EndPointAddr);
                //Specify Username-credential credentials
                ProxyClient.ClientCredentials.UserName.UserName = myUsername;
                ProxyClient.ClientCredentials.UserName.Password = myPassword;
                //Add request to field
                ProxyRequest.ProxyRequestField = ProxyDTRequest;
WordPress Appliance - Powered by TurnKey Linux