Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

Error in Connection of CRM with WebService

$
0
0

I am trying to Connect CRM with a WebService using C#.

But I am getting Error given below:

System.NullReferenceException  HResult=0x80004003  Message=Object reference not set to an instance of an object.  Source=Microsoft.Xrm.Tooling.Connector  StackTrace:   at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.get_CrmWebClient()   at Microsoft.Xrm.Tooling.Connector.CrmServiceClient.get_OrganizationWebProxyClient()   at ContactCreation.ConnectionClass.GetOrganizationServiceClientSecret(String clientId, String clientSecret, String organizationUri) in C:\Users\HamzaHafeez\source\repos\ContactCreation\ContactCreation\ConnectionClass.cs:line 41

Same connection code is working fine on Console and WebApp.

       

 

try
{

IOrganizationService service = GetOrganizationServiceClientSecret("My App ID", "My Secret ID", "https://MyURL/");

         if (service != null)

                {

                    

                    return "weldone";

                }

                return "Done";

            }

            catch (Exception ex)

            {

                throw ex;

            }

        }

        public IOrganizationService GetOrganizationServiceClientSecret(string clientId, string clientSecret, string organizationUri)

        {

            try

            {

                var conn = new CrmServiceClient($@"AuthType=ClientSecret; url={organizationUri}; ClientId={clientId}; ClientSecret={clientSecret}");

                return conn.OrganizationWebProxyClient != null ? conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

            }

            catch (Exception ex)

            {

                // Handle the exception here

                throw ex;

            }

        }

    }

}

Please help to solve the Error.Thank You


Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>