Skip to main content

Call web service from CRM with windows authentication - Sample Code

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



-

Let me know if you need any help
   
   
   
 
 
   
     
       
         
           
         
       
     
   
   
     
   
 
   
   
 
 
   
     
       
         
           
         
       
     
   
   
     
   
 

Comments

Popular posts from this blog

How to Integrate WhatsApp with Dynamics 365 Omnichannel – On Trial

How to Integrate WhatsApp with Dynamics 365 Omni Channel – On Trial Pre Requisites a.        Trail Environment with Customer Service Enabled, Preferably Netherlands as Location Ref : https://docs.microsoft.com/en-us/dynamics365/omnichannel/try-channels b.        Twilio Trial Account Ref : https://www.twilio.com/docs/usage/tutorials/how-to-use-your-free-trial-account#sign-up-for-your-free-twilio-trial Let’s Start the Configuration! Configuration: Dynamics 365 Channel Integration Framework - V2 1.        Go to dynamic 365 administration center via below link after logging to trial account https://port.crm4.dynamics.com/G/Applications/Index.aspx 2.        Make Sure Channel Integration Framework in Enabled, like in below screen shot else, configure it . By default, this should have enabled. Configuration: Omnichannel for Custo...

Delete record using JQuery and OData in Dynamics CRM 2011

function DeleteRecord(id, oDataSetName) {     var serverUrl = Xrm.Page.context.getServerUrl();     var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";     $.ajax({         type: "POST",         contentType: "application/json; charset=utf-8",         datatype: "json",         url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + id + "')",         beforeSend: function (XMLHttpRequest) {             //results will be returned as JSON.              XMLHttpRequest.setRequestHeader("Accept", "application/json");             //HTTP method DELETE               XMLHttpRequest.setRequestHeader("X-HTTP-Method", "DELETE");         },         success: function (da...

How to attach refresh event on Dynamic CRM 2011 subgrid using Java Script / JQuery ?

// Attach the function OnFormLoad event function OnFormLoad() {     setTimeout("SubGridRefresh();", 2500 ); } function   SubGridRefresh() {     var subgrid = document.getElementById("subgridid");     if (subgrid.readyState != "complete") {         // recursive till the subgrid is loaded         setTimeout(SubGridRefresh, 1000);         return;     }     // if subgrid fully loaded       if (subgrid) {         // attach the name of the custom function to grid          subgrid .attachEvent("onrefresh", OnRefresh_SubGrid);          subgrid .control.add_onRefresh(OnRefresh_SubGrid);     } } function   OnRefresh_SubGrid() {     //custom code to execute     var entityid = Xrm.Page.data.entity.getId();     alert(entityid); } ...