When calling secure old asmx web service using c# we cant directly add user name token to the soap header like WCF.we need to have Microsoft.Web.Services(Version) library.Microsoft has not shipped this library along with the .Net framework.Instead of that Microsoft has provided package called Web Services Enhancements which is a product that enables you to build secure Web services quickly and easily.
There are few versions for WSE. Downloaded and install latest version from below link(3.0).
after installed go to the below location.(my DEV machine is win7 64 bit version- path may change according to the your windows version)
Then add Microsoft.Web.Service3.dll reference to your project.
Then add the web service reference to the project and open reference.cs file.(to open that click show all files)
Open proxy file.
you can see our generated soap class inherited from SoapHttpClientProtocol. we need to change it to the Microsoft.Web.Services3.WebServicesClientProtocol .
Now we are done with the proxy class. then need to add the blow code to the web service client.