Skip to content

Call to WCF service from .net core 2.2 web api (MessageSecurityException) #3758

Open
@anucjs

Description

@anucjs

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..

Metadata

Metadata

Assignees

No one assigned

    Labels

    BlockedIssues blocked from completion for some specific reason.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions