Exactly now, I got my webservice authentication, but i've done this calling a method inside WebMethod, like this:
[WebMethod]
[SoapHeader("LoginSoapHeader")]
public int findNumberByCPF(string cpf)
{
try
{
LoginAuthentication();
var retRamal = DadosSmp_Manager.RetornaRamalPorCPF(cpf);
var searchContent= String.Format("CPF[{0}]", cpf);
DadosSmp_Manager.insertCallHistory(retRamal, searchContent);
return retRamal.Ramal;
}
catch (Exception ex)
{
Log.InsertQueueLog(Log.LogType.Error, ex);
throw getException(ex.TargetSite.Name, cpf);
}
}
I want now to authenticate this WebMethod without call the "LoginAuthentication()" method, only using the SOAP Header - SoapHeader("LoginSoapHeader") - that is above inside the code.
Then, my question is how can I authenticate my WebMethod only using headers?
Thanks in advance.
The requirement is the web service client has to provide with username and password while accessing the web methods.
We're going to achieve this using custom soap headers not the http headers
The .NET framework lets you create custom SOAP headers by deriving from the SoapHeader class, so we wanted to add a username and password
To force the use of our new SOAP Header we have to add the following attribute to the method
Include the class name in .cs
we authenticate using the soap:Header element in a SOAP request,don't misunderstand the HTTP headers sent with the request. The SOAP request looks something like: