how to pass Azure barer Token in Soap Request RRS feed

  • Question

  • User430178104 posted

    I'm consuming one of the third party webservice. currently for authentication i am passing network credentials for authentication purpose.....right now the requirement is changed to instead network credentials i need to pass Azure barear Token.

    I know how to pass Azure barer Token with httpclient (REST call) but can any one help to pass Azure barear Token in SoapRequest (WebService NOT WCF)

    Tuesday, July 31, 2018 7:56 AM

All replies

  • User475983607 posted

    I assume you mean ASMX and you want the bearer token in the HTTP header. 


    namespace WebFormsDemo
        public partial class AsmxClient : System.Web.UI.Page
            protected void Page_Load(object sender, EventArgs e)
            protected void Button1_Click(object sender, EventArgs e)
                string token = "123";
                ServiceReference2.WebService2SoapClient client = new ServiceReference2.WebService2SoapClient();
                using (new OperationContextScope(client.InnerChannel))
                    // Add a HTTP Header to an outgoing request
                    HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
                    requestMessage.Headers["Authorization"] = "Bearer " + token;
                    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
                    Label1.Text = client.HelloWorld();

    Web Service

        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        // [System.Web.Script.Services.ScriptService]
        public class WebService2 : System.Web.Services.WebService
            public string HelloWorld()
                HttpContext context = HttpContext.Current;
                return HttpContext.Current.Request.Headers["Authorization"];

    Keep in mind that SOAP has provisions, the WSDL, for passing tokens in the SOAP message.  I recommend that you contact the 3rd party service and ask for assistance.

    Tuesday, July 31, 2018 10:59 AM