How to add custom Http Header for C# Web Service Client consuming Axis 1.4 Web service

前端 未结 7 1764
离开以前
离开以前 2020-11-29 20:33

I\'m trying to write a web service client in c# which the webservice is Java Axis 1.4. Axis service requires the Authorization: Basic Base64EncodedToken hea

7条回答
  •  我在风中等你
    2020-11-29 20:58

    Are we talking WCF here? I had issues where the service calls were not adding the http authorization headers, wrapping any calls into this statement fixed my issue.

      using (OperationContextScope scope = new OperationContextScope(RefundClient.InnerChannel))
      {
                var httpRequestProperty = new HttpRequestMessageProperty();
                httpRequestProperty.Headers[System.Net.HttpRequestHeader.Authorization] = "Basic " +
                Convert.ToBase64String(Encoding.ASCII.GetBytes(RefundClient.ClientCredentials.UserName.UserName + ":" +
                RefundClient.ClientCredentials.UserName.Password));
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
    
                PaymentResponse = RefundClient.Payment(PaymentRequest);
       }
    

    This was running SOAP calls to IBM ESB via .NET with basic auth over http or https.

    I hope this helps someone out because I had massive issues finding a solution online.

提交回复
热议问题