简体   繁体   中英

CRM Dynamics SDK 2016 Throwing Error 3242

I have been working on a few weeks on a program to e-mail reminders about quotes. The program uses the CRM Dynamics 2016 SDK, leveraging early bound classes. The program connects to the CRM server, fetches data, and uses the aforementioned early bound classes to manipulate this data.

The core of my problems is based around the connection to the CRM server. It is connecting similar to the below:

var result123 = from r in xrm.QuoteSet where r.kro_QuotationNumber.StartsWith("123") select r;

The connection is configured in App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>


    <configSections>
      <section name="microsoft.xrm.client" type="Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client" />
    </configSections>

    <microsoft.xrm.client>
        <contexts>
          <add name="Xrm" type="Itelios.Crm.Business.Dynamics.XrmServiceContext" />
        </contexts>
    </microsoft.xrm.client>
    <connectionStrings>
        <add name="Xrm" connectionString="Server=https://crm.OrganizationName.com/XRMServices/2011/Organization.svc; Domain:OrganizationDomain; authtype=IFD; Username=username@OrganizationDomain.com; Password=password"/>
  </connectionStrings>

<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>

Here is the code of the connection in the main fonction :

    //To create the contexte, we should create an IOrganizationService
        OrganizationServiceProxy serviceproxy = null;
        try
        {
            ServerConnection server = new ServerConnection();
            server.ReadConfigurations();

            ServerConnection.Configuration config = server.configurations[0];
            //config = server.configurations.GetRange(1,1).First<ServerConnection.Configuration>();

            serviceproxy = new OrganizationServiceProxy(config.OrganizationUri, config.HomeRealmUri, config.Credentials, config.DeviceCredentials);
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
        serviceproxy.EnableProxyTypes();
        IOrganizationService service = (IOrganizationService)serviceproxy;


        ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };


        //CRM Context Creation
        using (var xrm = new Xrm(service)) { etc. }

The code was working until we tried to create a executable file from this program, so that it could be utilized as a schedule task, and be run from a different server. With a few tries, I conclude the problem I was facing wasn't due to the executable file, but due to the computer change.

I tried the following:

  1. Changing the authentication type to AD , instead of IFD
  2. Adding a line of code that could negate the Token security check
  3. Trying to get the code on this page working
    • In this one, I don't know what is a relying party though.
  4. Trying a lot of things around the connection String, all of them don't mess up with the working code, but don't seem to do anything either.
    • Removing the Organization Name part in the server connection.
    • Removing the /XRMServices/2011/Organization.svc since it's an IFD connection
    • Changing the attribute "Url" into "Server" or "ServiceUri"
    • Adding "LoginPrompt=Never" at the end of the connection String
  5. Adding Xrm.Tooling.Connector reference, using CrmServiceClient to connect to the server.

The error is happening right after fetching the data I've searched for with the request.

Does anyone have advice on how to resolve this error, or perhaps insight into why it is being thrown?

Nevermind, I found the root of my problems.

When I first started to use the SDK, I linked CrmServiceHelper as I said in my question. Although, since it was a very generic file, there was some libraries to install, especially Microsoft.IdentityModel. At this time, I didn't know it would be something crucial for my program to run, so I just commented the part concerning the Security Token.

While trying to re-install everything in another server, I found this the same bug, this time aware that Security Tokens were important.

Long story short, you have just to import Microsoft.IdentityModel from Nuget Package Tool Manager.

Since this problem was very related to connection disfunctionments, I was lured into thinking the bug was coming from the Connection part of my code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM