In todays age of technology, where data-interchange between systems is imminent. In some cases, it is the application interacting with each other or in some cases it will be the web services interacting with each other.
So, today, we will talk about how to add a SOAP header to your Web Service Call. i.e. if you are trying to call a web service, from your web service and you need to pass a SOAP header to each request you send to that service.
Commonly, web service access credentials are passed along with the service request.
This article assumes, you have a knowledge of:
- Web Services
- What is SOAP
- How to create a ASP .Net Web Service Project in Visual Studio.
Visual Studio IDE:
- Visual Studio 2013
So, lets get started:
Firstly, after your .Net Web Service project is created, right click on the Project name and click Add >> Service Reference
After you have added the service reference. A pop-up would appear as shown below:
Enter the Web Service URL that you need to connect to and click Go, to check the connectivity. If successfully connected, then enter the Namespace. In my case, the namespace is ‘ServiceReference’, and then click Ok.
The service reference will show up under Service References section as shown below:
Now, lets open the Web.Config file and edit few things there. As you may see in the screen grab below, a new tag is added into the Web.Config by name name system.serviceModel. It is here that your web service bindings and endpoint details are mentioned.
Notice the endpoint tag is closing in-line. Which means, it does not have a separate closing tag
Now, remove the inline closing tag for Endpoint and add a separate closing tag for Endpoint as
After you do that, add the below tags in the endpoint tag as shown below:
Now, the headers will be attached with each of your SOAP request.
I hope, this blog helps you with your problem.