Call (Consume) SOAP WCF Service with Basic Credentials using C# in ASP.Net

Last Reply 8 months ago By alibasha

Posted 8 months ago


How to Consume WCF Rest Service which has Basic Credentials (authentication) From Web Application (no Jquery approach please).

WCF Rest Service team gave me 2 type of credentials, using which I need to call and access their methods.

1. Basic Credentials

    User Name: abc

    Pass word : 123

2. Credentials Need to pass for every call to the service to access each method

    User Name: xyz

    Password: 123

Thanks in advance.

Posted 8 months ago

Hi All,

Actually it is a SOAP service, because after I added the service refeference, below entry is made in config file.

  <endpoint address=""
  binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IFinance"
  contract="ServiceReference_REDF.IFinance" name="WSHttpBinding_IFinance">
      <dns value="" />

We need to call their the service like below.

ServiceReference_REDF.Credential objCredential = new ServiceReference_REDF.Credential();//This Credential class is their's 
objCredential.UserName = UserName;//Credentials to access each method.
objCredential.Password = Password;
ServiceReference_REDF.FinanceClient objCalc = new ServiceReference_REDF.FinanceClient();
objCalc.ClientCredentials.UserName.UserName = "redfweb";//Basic authentication,Credentials to access the service
objCalc.ClientCredentials.UserName.Password = Password;
var objREDFResponseBanks = objCalc.getBanks(objCredential);

Also our IP(client) should be whitelisted in their server. Their server firewall should not block us.