Since the Component integration does not support .NET Core, I am trying to do a Protocol Integration.
But I am having some difficulties when I call the Login method on the web service. I get the following error:
The HTTP request is unauthorized with client authentication scheme ‘Ntlm’. The authentication header received from the server was ‘Basic realm=“localhost”’.
I have used the “Add connect service” tool in Visual studio to import the ServerCommandService as a connect service (SOAP service).
Here is the the code I use:
public string Login()
{
var uri = new Uri($"https://{ConfigurationManager.AppSettings["server"]}/ManagementServer/ServerCommandService.svc");
var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
var factory = new ChannelFactory<ServerCommandServiceSoap>(binding, new EndpointAddress(uri));
factory.Credentials.ServiceCertificate.SslCertificateAuthentication =
new X509ServiceCertificateAuthentication
{
CertificateValidationMode = X509CertificateValidationMode.None,
RevocationMode = System.Security.Cryptography.X509Certificates.X509RevocationMode.NoCheck
};
factory.Credentials.Windows.ClientCredential.Domain = ConfigurationManager.AppSettings["domain"];
factory.Credentials.Windows.ClientCredential.UserName = ConfigurationManager.AppSettings["username"];
factory.Credentials.Windows.ClientCredential.Password = ConfigurationManager.AppSettings["password"];
var serviceProxy = factory.CreateChannel(new EndpointAddress(uri));
LoginInfo loginInfo;
try
{
using (var scope = new OperationContextScope((IContextChannel) serviceProxy))
{
((ICommunicationObject)serviceProxy).Open();
loginInfo = serviceProxy.LoginAsync(Guid.NewGuid(), "").Result;
}
var token = loginInfo.Token;
return token;
}
catch (Exception e)
{
Console.WriteLine("Unable to login: " + e.Message);
Console.WriteLine("Press any key to close application...");
Console.ReadLine();
return "";
}
}
Could you please provide a working example on how to call the SOAP web service from a .NET Core 2.2 application?