Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Consume wcf service from asp.net core Credentials not found

$
0
0

I have added a service reference with Visual studio WCF connected service.

When i try to consume i receive the exception that the credentials are not found.

I´ve been able to consume this service in asp.net mvc but to make this work i made a trick to overriding the headers in the request:

 

 public class AgendasWs2 : CatalogosAgendasWS_A
    {
        protected override System.Net.WebRequest GetWebRequest(Uri uri)
        {

            HttpWebRequest request;
            request = (HttpWebRequest)base.GetWebRequest(uri);

            if (PreAuthenticate)
            {
                NetworkCredential networkCredentials = Credentials.GetCredential(uri, "Basic");
                if (networkCredentials != null)
                {

                    byte[] credentialBuffer = new UTF8Encoding().GetBytes(networkCredentials.UserName + ":" + networkCredentials.Password);

                    request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(credentialBuffer);
                }
                else
                {
                    throw new ApplicationException("No network credentials");
                }
            }
            return request;
        }
    }

As you can see i override the headers before sendind the request.

The service has a Preemptive authentication type

I dont have any idea of making this in asp.net core.

Any help :)


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>