0

I have a webservice e.g.

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class SI_C : System.Web.Services.WebService {

public SI_C()
{

    //Uncomment the following line if using designed components 
    //InitializeComponent(); 
}

[Webmethod]

public bool CreateRecord(classname objname) //some class I am setting the data to
{
   //Creates a record.
}
}

Now while consuming at client side I created

 SI_C_In_SoapClient client = new SI_C_In_SoapClient("SI_C");
 client.ClientCredentials.UserName.UserName = "Username Sent";
 client.ClientCredentials.UserName.Password = "Passport Sent";

Now I want to access this sent password and username in my webservice. How would I do that?

Update:

  1. Set the password and username at client side using network credentials call
  2. Receive that in webservice
  3. Send to database and check if ok? That's it.
TestinGuy
  • 21
  • 5

1 Answers1

1

This is mostly dependent upon how you configured your web server app. If using IIS then the answer to this question is entirely driven by how you set up security.

Look into HttpContext.Current.User or CredentialCache.DefaultNetworkCredentials here is the link:

Respectively:

How does HttpContext.Current.User.Identity.Name know which usernames exist?

https://learn.microsoft.com/en-us/dotnet/api/system.net.credentialcache.defaultnetworkcredentials?redirectedfrom=MSDN&view=netframework-4.8#System_Net_CredentialCache_DefaultNetworkCredentials

T McKeown
  • 12,971
  • 1
  • 25
  • 32
  • I just want to access the credentials in the web service that are being set in client app before calling. – TestinGuy Sep 26 '19 at 14:03
  • are you using integrated security? you need to detail how your security is configured on the web server. If the security is set to integrated then `HttpContext.Current.User` is what you are looking for. – T McKeown Sep 26 '19 at 14:04
  • I will just check the username and password against the database. – TestinGuy Sep 26 '19 at 14:06
  • 1. Set the password and username at client side using network credentials call 2. Receive that in webservice 3. Send to database and check if ok? That's it. – TestinGuy Sep 26 '19 at 14:06
  • huh??? a web service isn't going to work with sql server authentication... – T McKeown Sep 26 '19 at 14:06
  • I just want to get those set credentials in webservice. that;s it – TestinGuy Sep 26 '19 at 14:07
  • 1
    I am not understanding what you are telling me. doesn't make sense. – T McKeown Sep 26 '19 at 14:08
  • @T McKeown: See, I have a client app from where I am calling web service (that's mine too). Now at client side I am setting credentials using NetworkCredentials class. So, after calling the webservice, at that end I want to get those credentials. That's it. – TestinGuy Sep 28 '19 at 08:07