Double request while making POX REST call using WCF with WebHttpBinding set to Basic Authentication

前端 未结 2 1995
借酒劲吻你
借酒劲吻你 2021-01-15 16:24

Having an issue while making POX REST call using WCF with WebHttpBinding set to Basic Authentication (HttpClientCredentialType.Basic)

Instead of one call from the cl

2条回答
  •  孤街浪徒
    2021-01-15 16:43

    So based on Remus's answer this is my workaround

            public Message SendData(Message requestMessage)
        {
            var channel = CreateChannel();
            Message responseMessage;
            using (new OperationContextScope((IClientChannel)channel))
            {
                WebOperationContext.Current.OutgoingRequest
                    .Headers[HttpRequestHeader.Authorization] = "Basic "
                    + Convert.ToBase64String(Encoding.ASCII.GetBytes(
                    Credentials.UserName.UserName + ":" + Credentials.UserName.Password));
                responseMessage = channel.SendData(requestMessage); 
            }
            return responseMessage;
        }
    

    I'm simply forcing first request to go out with Basic Authorization

提交回复
热议问题