Adding SOAP Header to ASP.Net Web Service

Hello All,

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:

  1. .Net
  2. Web Services
  3. What is SOAP
  4. How to create a ASP .Net Web Service Project in Visual Studio.

Visual Studio IDE:

  1. 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

Untitled.png

After you have added the service reference. A pop-up would appear as shown below:

test.png

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.

Servicerefernece.png

The service reference will show up under Service References section as shown below:

solution.png

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.

webconfgig.png

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

webconfgig.png

After you do that, add the below tags in the endpoint tag as shown below:

Webconfig2.png

Now, the headers will be attached with each of your SOAP request.

I hope, this blog helps you with your problem.

-Cheers!

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s