Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

Error in Connection of CRM with WebService

Posted on by 5

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

  • Hamza Profile Picture
    Hamza 5 on at
    RE: Error in Connection of CRM with WebService

    Abdul Wahab Hi,

    My code is working fine on console and web APP. But I am getting Error in Web Service

  • Suggested answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: Error in Connection of CRM with WebService

    Hi Hamza Bhatti,

    The link: learn.microsoft.com/.../quick-start-org-service-console-app might be the solution to your problem. Please follow.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans