Call wcf web service with windows authentication - Sample Code
Sample Code to Consume Web Service
private SurveyWrapperServiceClient CreateClientService()
{
try
{
SurveyWrapperServiceClient _WrapperClient = new SurveyWrapperService.SurveyWrapperServiceClient();
string Domain = WebConfigurationManager.AppSettings["SurveyModule.ProxyDomain"].ToString();
string User = WebConfigurationManager.AppSettings["SurveyModule.ProxyUser"].ToString(); ;
string Password = EncryptionHelper.GetDecodedText(WebConfigurationManager.AppSettings["SurveyModule.ProxyUserPassword"].ToString());
_WrapperClient.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(User, Password, Domain);
return _WrapperClient;
}
catch (Exception ex)
{
Log.Error("Xrm.Survey.Online.CreateClientService:Exception");
Log.Error(ex.Message.ToString() + "--" + ex.StackTrace.ToString()); throw;
throw;
}
}
Web.Config of the WCF Service
-----------------------------------------------------------
Make sure the web.config is like below for the WCF
Sample Code to Consume Web Service
private SurveyWrapperServiceClient CreateClientService()
{
try
{
SurveyWrapperServiceClient _WrapperClient = new SurveyWrapperService.SurveyWrapperServiceClient();
string Domain = WebConfigurationManager.AppSettings["SurveyModule.ProxyDomain"].ToString();
string User = WebConfigurationManager.AppSettings["SurveyModule.ProxyUser"].ToString(); ;
string Password = EncryptionHelper.GetDecodedText(WebConfigurationManager.AppSettings["SurveyModule.ProxyUserPassword"].ToString());
_WrapperClient.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(User, Password, Domain);
return _WrapperClient;
}
catch (Exception ex)
{
Log.Error("Xrm.Survey.Online.CreateClientService:Exception");
Log.Error(ex.Message.ToString() + "--" + ex.StackTrace.ToString()); throw;
throw;
}
}
Web.Config of the WCF Service
-----------------------------------------------------------
Make sure the web.config is like below for the WCF
-
Let me know if you need any help

Comments