Hello I have a wcf service i need to call but it still respond me with error:
System.ServiceModel.Security.MessageSecurityException: 'The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'NTLM, Negotiate'.'
My code looks like below:
Client creation:
var binding = CreateBinding();
var endpoint = new EndpointAddress(_settings.Endpoint);
var client = new VoucherService.VoucherServiceClient(binding, endpoint);
Binding:
private static BasicHttpBinding CreateBinding()
{
var binding = new BasicHttpBinding
{
ReceiveTimeout = TimeSpan.FromMinutes(10),
SendTimeout = TimeSpan.FromMinutes(10),
MaxReceivedMessageSize = 33554432,
TransferMode= TransferMode.Buffered,
Security = new BasicHttpSecurity
{
Mode = BasicHttpSecurityMode.TransportCredentialOnly,
Transport = new HttpTransportSecurity
{
ClientCredentialType = HttpClientCredentialType.Ntlm
}
}
};
binding.ReaderQuotas.MaxArrayLength = 32000;
return binding;
}
and call:
var response = client.Send(/*some data*/)
There is old .net4 solution i took configuration from. And there it works and i can calls service but in new .net 6 solution with the same configuration i am receiving error like at the top. Can you suggest me anything i can check what else is missing? Thanks!
In .NET 6.0 and above, a Reference.cs file is usually generated after the WCF service is called.
In this file there is a self-generated method:
My suggestion is to check if the configuration is the same as the WCF service.
Finally you use the parameterless constructor