I have an asmx web service and a test console app. I have added web service reference to the console app and calling it like this
Employee.Employee e = new TestService.Employee.Employee();
e.SomeMethod();
On every web service call there is a validation check which looks like this
private bool IsUserNameTokenPresent()
{
//Get current SOAP context
SoapContext ctxt = RequestSoapContext.Current;
UsernameToken user = null;
if (ctxt == null)
{
//This request is using a different protocol other than SOAP.
return false;
}
//Iterate through all Security tokens
foreach(SecurityToken tok in ctxt.Security.Tokens)
{
if (tok is UsernameToken)
{
user = (UsernameToken)tok;
}
}
if (user == null)
return false;
return true;
}
Question: How do I pass the Security Token so that I can test this service. Its always null.
Finally found the answer for this. I had to create my own SOAP header manually and pass it with the request. Here is some code. I had to create Nonce dynamically for every call, I will post it here if someone wants the code for that.