I began a POC project yesterday to connect to an existing WCF service and I am using a .Net Core 2.1 Web API application and Swagger to post my test request messages. I am using BasicHttpBinding and Transport for BasicHttpSecurityMode.
When sending at test request message, I’m receiving the following exception:
"The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic Realm'."
I then created a Microsoft Web API project using .NET Framework 4.6.1 to call the WCF service and I was able to get a Status Code 200 HTTP response.
This seems to me like an issue with a .NET Core 2 Web API project connecting to the WCF service. I’ve done some research and it looks like this design architecture should definitely be possible.
Microsoft has even developed a provider tool to do exactly this, here is a link to the MS article on the their provider tool: https://learn.microsoft.com/en-us/dotnet/core/additional-tools/wcf-web-service-reference-guide
I have even tried to have my .NET Core Web API controller call a handler class I built in a .NET 4.6.1 class library project to no avail, I still got the “The HTTP request is unauthorized with client authentication scheme 'Basic'. The authentication header received from the server was 'Basic Realm'.” exception.
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_IInsuranceService))
{
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
result.MaxBufferSize = int.MaxValue;
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
result.MaxReceivedMessageSize = int.MaxValue;
result.AllowCookies = true;
result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
return result;
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}
private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_IInsuranceService))
{
return new System.ServiceModel.EndpointAddress("https://myservicebaseURL\myservice.svc");
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}