1

Trying to consume a Web Service with C#, the service requires client credentials, setting up the credentials following some searching, still can't get it work

CustomSoapClient client = new CustomSoapClient ();
client.ClientCredentials.UserName.UserName = "myusername";
client.ClientCredentials.UserName.Password = "magicpassword";

Caching the Exception said “No credentials are available in the security package”. I tried to use the following line and still didn't work

client.ClientCredentials.HttpDigest.ClientCredential = new System.Net.NetworkCredential("myusername", "magicpassword", "domainjustincase");

I used SoaPUI to connect with the service and noticed than didn't work filling the request properties with "myusername", "magicpassword", "domainjustincase" and with the option of Authentication Type to Basic, because the service reject the request, and after a few minutes I'd changed to No Autorization and did it work, obviously keeping filled the request properties with "myusername", "magicpassword", "domainjustincase"

enter image description here

I'll aprecciate any help. Thanks in advance.

Luis Ibañez
  • 11
  • 2
  • 4

2 Answers2

0

I resolved the issue following this link Calling a SOAP service in .net Core

        public static async Task<string> ReadAsset()
        {
            try
            {
                var channel = SetChannel();
                var result = await channel.ReadAsync(new Read(queryitem));
                return result;
            }
            catch (Exception ex)
            {
               //Nothing
               return string.Empty;

            }
        }
        private static CustomSoapClient SetChannel()
        {
            var mode = BasicHttpSecurityMode.TransportCredentialOnly;
            var binding = new BasicHttpBinding(mode);
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
            var address = new EndpointAddress("mycustomurl");
            ChannelFactory<CustomSoapClient> channel = new ChannelFactory<CustomSoapClient>(binding, address);
            channel.Credentials.Windows.ClientCredential.UserName = "myusername";
            channel.Credentials.Windows.ClientCredential.Password = "magicpassword";
            channel.Credentials.Windows.ClientCredential.Domain = "domainjustincase";
            return channel.CreateChannel();
        }
Luis Ibañez
  • 11
  • 2
  • 4
0

I got the samme error message, albeit in a slightly different scenario. In my case the new credentials had not taken effect on my machine, and I solved it by restarting my machine, but not before wasting time on other approaches.

Halvard
  • 3,891
  • 6
  • 39
  • 51