locked
CrmConnection Did not work anymore in MS CRM Dynamics Update 2015 RRS feed

  • Question

  • We develop a Web Api that connects to out CRM Dynamics. We use our webapi to get our leads in CRM. Its was working, but now we cant connect anymore.

    We think its the Authentication. How are we able to connect to CRM Dynamics using the class CrmConnection.

    Do I have to register our webapi in Azure? And use the ClientId to authenticate?

    Friday, September 18, 2015 6:19 PM

All replies

  • Hi Bruno,

    You dont have to register your webapi in Azure..

     String X = "Url=" + OrganizationUrl + ";";
     X += " Domain="+Domain+"; Username=" + UserName + "; Password=" + Password + "";
    
    IOrganizationService _service = CrmConfigurationManager.CreateService(CrmConnection.Parse(X), "myservice") as IOrganizationService;

    Also you need add below tags into the Web.config file.

    <configSections>
        <section name="microsoft.xrm.client" type="Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client"/>
     </configSections>
    
    <microsoft.xrm.client>
        <contexts>
          <add name="Xrm" type="Xrm.XrmServiceContext, Xrm" serviceName="MyService"/>
        </contexts>
        <services>
          <add name="myservice" type="Microsoft.Xrm.Client.Services.OrganizationService, Microsoft.Xrm.Client" instanceMode="PerRequest"/>  
        </services>
      </microsoft.xrm.client>


    If you find this post helpful then please Vote as Helpful and Mark As Answer. Thanks and Regards, Polat Aydın My blog

    Monday, September 21, 2015 9:25 AM
  • Hello Aydin

    Thanks for your reply.

    My connection is pretty the same:

    CrmConnection connection = CrmConnection.Parse(ConfigurationManager.ConnectionStrings["UserAndPswrd"].ConnectionString);

    But its failling:

    An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.

    I am not sure if is able to connect to MS CRM Dynamics like that. Because now the have their own Web Api (the webapi preview).

    I checking out your blog, there are good content there.

    Thanks :)

    Tuesday, September 22, 2015 2:27 PM
  • Hi Bruno,

    I connect from MVC application to CRM with the code that ı sent you.It gives the exception CrmConnection.Parse statement? Also can you post your all code and the exception in a detail view , so ı can help you more.


    If you find this post helpful then please Vote as Helpful and Mark As Answer. Thanks and Regards, Polat Aydın My blog


    Thursday, September 24, 2015 11:57 AM
  • Hello, a simple example of my code. I removed some comments too.

    Thanks for your help.

    We implemented just one method:

    using System;
    using System.Web.Http;
    using System.Configuration;
    using Microsoft.Xrm.Client;
    using Microsoft.Xrm.Client.Services;
    using Microsoft.Xrm.Sdk;
    using System.Web.Http.Cors;
    using System.Net.Http.Formatting;
    using System.Web;
    using Microsoft.Xrm.Sdk.Query;
    using System.Collections;
    
    namespace CRMLead.Controllers
    {
    
        [EnableCors(
            origins: "http://localhost:54163",
            headers: "*",
            methods: "get")]
        public class CRMLeadController : ApiController
        {
            private OrganizationService _orgService;
    
            public IEnumerable Get()
            {
                CrmConnection connection = CrmConnection.Parse(ConfigurationManager.ConnectionStrings["CRMOnlineO365"].ConnectionString);
    
                using (_orgService = new OrganizationService(connection))
                {
                    QueryExpression query = new QueryExpression
                    {
                        EntityName = "lead",
                        ColumnSet = new ColumnSet("fullname", "leadid")
                    };
    
                    return _orgService.RetrieveMultiple(query).Entities;
                }
    
            }
    
        }
    }
    

    Exception:

    An exception of type 'System.ServiceModel.Security.MessageSecurityException' occurred in Microsoft.Xrm.Sdk.dll but was not handled in user code

    <ExceptionMessage>
    An error occurred when processing the security tokens in the message.
    </ExceptionMessage>
    <ExceptionType>System.ServiceModel.FaultException</ExceptionType>
    <StackTrace/>

    Thursday, September 24, 2015 6:44 PM