Call to WCF service from .net core 2.2 web api (MessageSecurityException)
- Dominant language
- C#
- Stars
- 1.8k
- Forks
- 576
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 2
Description
Hi,
I am trying to consume WCF service from .net core web api client app. The service needs following three settings on client side:
1) Custom HTTP headers to pass user email and ID
2) Client Credentials settings as :
credentials.Windows.ClientCredential.Domain = Domain;
credentials.Windows.ClientCredential.UserName = UserName;
credentials.Windows.ClientCredential.Password = Password;
credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Delegation;
3) userPrincipalName from app.config
When I pass above info from windows app client(NOTE: this client is not .net core windows app but just .net windows app), i am able to call service methods correctly.
To reflect above settings in .net core web api app, i have made following changes:
1) using (new OperationContextScope(clientObj.InnerChannel))
{
// Add a HTTP Header to an outgoing request
HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
requestMessage.Headers[user_email] = "some text";
requestMessage.Headers[user_id] = "some text";
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
}
2)
ContractServiceClient clientObj = new ContractServiceClient(ContractServiceClient.EndpointConfiguration.WSHttpBinding_IContractService);
NetworkCredential myCreds = new NetworkCredential("user", "pwd", "AMR");
clientObj.ClientCredentials.Windows.ClientCredential = myCreds;
clientObj.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;
3) UpnEndpointIdentity endpointIdentity2 = new UpnEndpointIdentity("email.com");
if ((endpointConfiguration == EndpointConfiguration.WSHttpBinding_IContractService))
{
return new System.ServiceModel.EndpointAddress(new System.Uri("servicename.svc"), endpointIdentity2, null);
}
After this, i get following exception in .net core web api client:
MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate, NTLM, Basic realm="service name"
Any pointers highly appreciated. Thanks in advance..
Contributor guide
Research direction
Start with the generated ContractServiceClient configuration and the OperationContextScope code shown in the issue, then compare those settings with the working Windows client. Reproduce the call and inspect the service's Negotiate, NTLM, and Basic challenge; done means identifying the compatible client authentication and endpoint identity configuration or documenting that the requested setup is unsupported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100