I'm running an application on .net core 2.1. I added a wsdl web service through connected services that generated me a WcfServiceClient successfully.
When using Basic Autorization it works fine.
here is the class I use for calling a helloword soap method :
public string HellowWorld(string input)
{
string wsRes = null;
try
{
var service = new WorkerProcessServiceClient();
var url = $"http://ServerUrl/Directory/WsName.svc";
UriBuilder uriBuilder = new UriBuilder(url);
service.Endpoint.Address = new EndpointAddress(uriBuilder.Uri);
service.ClientCredentials.UserName.UserName = Username;
service.ClientCredentials.UserName.Password = Password;
using (OperationContextScope scope = new OperationContextScope(service.InnerChannel))
{
HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers[System.Net.HttpRequestHeader.Authorization] =
"Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(service.ClientCredentials.UserName.UserName
+ ":"
+ service.ClientCredentials.UserName.Password));
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
wsRes = service.HelloWorldAsync(input, RetailContext).GetAwaiter().GetResult();
service.Close();
}
}
catch (Exception ex)
{
wsRes = ex.Message;
}
return wsRes;
}
This is working fine with servers that are running on Basic Authorization. I am using the same credentials with SOAP UI and it is working very well. and I dont even need to specify the
<==> Now The Problem <=>
I have a second server that runs with NTLM Authorization. I done it all :'( but nothing seems working.
1 - I changed my service.clientCredential.Username
to service.clientCredential.Windows
and I added service.clientCredential.Windows.domain
2 - I changed the Header also from "Basic " + Convert...
to "Ntlm " + Convert...
3 - I added the domain in the header and I put it first and last position.
when I use SOAP UI, it is working just fine.
I dont know what to do else Please Help.