Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Error in Connection of CRM with WebService

(0) ShareShare
ReportReport
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

  • CU24041021-0 Profile Picture
    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
    12,085 Moderator 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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 671 Super User 2025 Season 1

#2
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 167 Super User 2025 Season 1

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 138 Most Valuable Professional

Product updates

Dynamics 365 release plans