How to add http header to webservice soap request C#

cK 1 Reputation point
2021-07-19T05:08:19.697+00:00

I need to add http header to webservice soap request using C#. Already I created webservice proxy using wsdl.exe. But I searched the code in stackoverflow, MSDN forum and found it is available for soapclient, and HttpWebRequest webRequest . Can I know how to add http header to web service request ? (but the existing project has webservice proxy- the service proxy created using wsdl.exe)

Developer technologies ASP.NET Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,096 Reputation points
    2021-07-19T10:02:38.65+00:00

    Hi @cK ,
    You could try these codes:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create( Your URL );  
    request.Headers.Add( "SOAPAction", YOUR SOAP ACTION );  
    

    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2021-07-19T17:50:41.477+00:00

    its pretty simple:

    1) create a class that inherits from the generated proxy class
    2) override the method GetWebRequest
    3) in the override method, add code like above to set set the header

    use this new class instead of the original.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.