I have a legacy WCF service with custom binding. I want to invoke this service from a .Net Standard 2.0 client. I have added nuget packages system.servicemodel.primitives, system.servicemodel.security and system.servicemodel.security. Below is my channel factory setup
var binding = new CustomBinding();
var security = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
security.IncludeTimestamp = true;
binding.Elements.Add(security);
binding.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Default, Encoding.UTF8));
binding.Elements.Add(new HttpsTransportBindingElement { MaxBufferSize = MaxBufferSize, MaxReceivedMessageSize = MaxReceivedMessageSize });
var headers = new Dictionary<string, string>
{
{"Ocp-Apim-Subscription-Key","xxxxxxxxxxxxxxxxxxxxxxx"}
};
var behaviour = new AddHttpHeaderMessageEndpointBehavior(headers);
ChannelFactory<ITaskService> cf = new ChannelFactory<ITaskService>(binding, new EndpointAddress("https://api-xxl.yyy.com/cvg/fg/swer/v1"));
cf.Endpoint.EndpointBehaviors.Add(behaviour);
cf.Credentials.UserName.UserName = "username";
cf.Credentials.UserName.Password = "password";
I get the below error
"HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'AzureApiManagementKey"
I am able to successfully invoke the API from a .Net Framework client. The only difference is
binding.Elements.Add(new TextMessageEncodingBindingElement(**MessageVersion.Soap12**, Encoding.UTF8));
Can someone advise me what is the solution?