none
Replace ClientCredentials with token Bearer header in OperationContextScope SOAP request RRS feed

  • Question

  • Hi, I am requesting a SOAP service with WCF and .NET Core. For authorization I have used ClientCredentials but know the service changed authorization to token Bearer and I get "System.ServiceModel.FaultException: 'Validation error'" when trying to use 

     using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
          {
            HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();

            httpRequestProperty.Headers.Add("Authorization", "Bearer " + "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx");

           OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] =      httpRequestProperty;

           ........

          }

    I have also tried 

            MessageHeader tokenHeader = MessageHeader.CreateHeader("Bearer",          "https://api.lantmateriet.se/distribution/produkter/taxering/v1.7", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx");
            OperationContext.Current.OutgoingMessageHeaders.Add(tokenHeader);

    but with no luck so please help!

    Sunday, January 12, 2020 3:10 PM

All replies

  • Hi, I am requesting a SOAP service with WCF and .NET Core. For authorization I have used ClientCredentials but know the service changed authorization to token Bearer and I get "System.ServiceModel.FaultException: 'Validation error'" when trying to use 

     using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
          {
            HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();

            httpRequestProperty.Headers.Add("Authorization", "Bearer " + "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx");

           OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;

           ........

          }

    I have also tried 

            MessageHeader tokenHeader = MessageHeader.CreateHeader("Bearer", "https://api.lantmateriet.se/distribution/produkter/taxering/v1.7", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx");
            OperationContext.Current.OutgoingMessageHeaders.Add(tokenHeader);

    but with no luck so please help!

    Sunday, January 12, 2020 11:07 AM
  • WCF can be discussed at the WCF forum.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wcf

    Sunday, January 12, 2020 12:28 PM
  • Hi,

    Merely according to your description, I don’t know the authentication mode on the server-side. thereby, I am also not sure which way is right.
    Usernametoken usually applies on in the SOAP envelops, that is SOAP message header. Therefore, the second way might be feasible.
    https://i.stack.imgur.com/XYTqD.png
    Anyhow, only we know the configuration on the server-side can lead to the right direction to the issue. Please post the complete configuration located on the server-side so that I can provide an effective reply.
    Feel free to let me know if there is anything I can help with.
    Best Regards
    Abraham

    Tuesday, January 14, 2020 5:59 AM
    Moderator