How can I add authorization header to the request in WCF?

前端 未结 4 1515
后悔当初
后悔当初 2020-12-10 17:03

I\'m working on a Windows Form application and there\'s a WCF service that needs to be called. I need to add a header (authorization - custom) to the request before it\'s se

4条回答
  •  渐次进展
    2020-12-10 17:07

    The problem with your solution is that it would add an HTTP header. What you need is a SOAP header, however. That could be done like this...

    using(new OperationContextScope(client.InnerChannel)) 
    {
        // Add a SOAP Header to an outgoing request
        MessageHeader aMessageHeader = MessageHeader.CreateHeader("UserInfo", "http://tempuri.org", userInfo);
        OperationContext.Current.OutgoingMessageHeaders.Add(aMessageHeader);
    }
    

提交回复
热议问题