web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Connection to Dynamics 365 through C#

(0) ShareShare
ReportReport
Posted on by 7

Hi,

I am using C# to connect to Dynamics 365. I used the same code and it works for one instance and not for another one. I get the following error : "ID3007: The element 'pp' with namespace 'schemas.microsoft.com/.../SOAPFault' is unrecognized."

I have the "Microsoft.CrmSdk.CoreAssemblies" package installed V 9.0.2.12 and targeting the .NET Framework 4.7.2.

the first instance in CRM that works fine with my code is a free trial with Server version: 9.1.0000.6227

the second instance that is giving me the error is another free trial with Server version: 9.1.0000.6421. I even tried to connect to the second instance using the Microsoft Dynamics 365 Plugin Registration Tool Version 9.0.0.9479 64 bit and it is not connecting

The code is the following

namespace ConnectToCRM {
	class Program {
		static void Main(string[] args) {
			
				try
				{
					IOrganizationService organizationService = null;

					ClientCredentials clientCredentials = new ClientCredentials();
					clientCredentials.UserName.UserName = "y@MyDomain.onmicrosoft.com";
					clientCredentials.UserName.Password ="MyPass";

					// For Dynamics 365 Customer Engagement V9.X, set Security Protocol as TLS12
					ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
					// Get the URL from CRM, Navigate to Settings -> Customizations -> Developer Resources
					// Copy and Paste Organization Service Endpoint Address URL 
					organizationService = (IOrganizationService)new OrganizationServiceProxy(new Uri("">MyDomain.api.crm12.dynamics.com/.../Organization.svc"),
					null, clientCredentials, null);

					if (organizationService != null)
					{
						Guid userid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).UserId;

						if (userid != Guid.Empty)
						{
							Console.WriteLine("DOTNET 2015 : Connection Established Successfully...");
						}

					}
					else
					{
					Console.WriteLine("DOTNET 2015 : Failed to Established Connection!!!");
					}
				}
				catch (Exception ex)
				{
				Console.WriteLine("DOTNET 2015 : Exception caught - " + ex.Message);

				}
			Console.ReadKey();

			

		}
	}
}


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Nflannery Profile Picture
    360 on at

    That seems strange,  raise a support request with microsoft.

  • YaraZ Profile Picture
    7 on at

    How do I do that?

  • Suggested answer
    Nflannery Profile Picture
    360 on at

    Go to portal.office.com and then admin then raise a support call. Its on the right hand side.

  • Guido Preite Profile Picture
    54,086 Moderator on at

    you can use a connection string and use the constructor of CrmServiceClient, it's the easiest way

    string crmConnectionString = "AuthType='Office365'; Url='mydomain.crm12.dynamics.com'; Username='y@MyDomain.onmicrosoft.com'; Password='MyPass';"

    CrmServiceClient service = new CrmServiceClient(crmConnectionString);

    and the connection string you can put inside your app.config/web.config and read it from there

  • YaraZ Profile Picture
    7 on at

    Thank you Guido Preite  for your response.

    I tried what you said as the following :

                try
                {
                    string crmConnectionString = ConfigurationManager.ConnectionStrings["MyCRMServer"].ConnectionString;
                    CrmServiceClient conn = new CrmServiceClient(crmConnectionString);
                    Console.WriteLine("Connection Established Successfully...");
                }

                catch (Exception ex)
                {
                    Console.WriteLine("Exception caught - " + ex.Message);
                }

    I didn't get an error, however when i tried to create the IOrganizationService it was always null. I debugged and looked further in the CrmServiceClient conn variable and it has "LastCrnError" attribute and it says : "CRMOrganizationWebProxyClient is null - OrganizationWebProxyClient is nullOrganizationWebProxyClient is null - OrganizationWebProxyClient is null.

    How can I create an organisation service and get the user Id from the CrmServiceClient?

    Besides, why wouldn't I be able to connect through the Plugin registration tool ?

  • Guido Preite Profile Picture
    54,086 Moderator on at

    you don't need to create an IOrganizationService, the CrmServiceClient object (that you named "conn" in your code) implements already IOrganizationService, so you can do conn.Retrieve, conn.Create, etc etc (this is also the reason I called it "service" in my code)

  • Suggested answer
    YaraZ Profile Picture
    7 on at

    I resolved the problem

    it was with the server crm12. apparently it is a new server and it is having problems managing connections.

    Initially my free trial was in France so it was automatically having the uri of crm12 region.

    i created another free trial (a third one) and put the country to spain  so i had crm4 and the code worked perfectly fine and i could connect with the plugin registration tool.

  • Guido Preite Profile Picture
    54,086 Moderator on at

    Hi YaraZ,

    thanks for let us know about this new region (crm12) Microsoft updated the SDK to handle the new region (link to my blog post) so if you update the SDK in your project you should be able to connect to your first trial.

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at

    Hi,

    Please refer code mentioned in below compiler:

    [View:https://rextester.com/LKPJF39412:750:50]

    Also refer below screenshot for connection string 

    pastedimage1563515931616v2.png

  • YaraZ Profile Picture
    7 on at

    Hi Guido,

    Thank you for this update. indeed my code works fine without changing or updating anything.

    And I installed the latest version of the plugin registration tool (9.0.2.22) and now it works too

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans