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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

The minimal way to create a customer in a retail DB with CRT and .NET

(0) ShareShare
ReportReport
Posted on by

Hello,

I have to write a C# app who insert a customer on a Retail channel database, using CRT (the app will actually do a lot more at the end, but I'm focus on this job currently).

I try to do it in the most simple way for now, times to understand how it works.

Some precisions to begin :
- I'm a complete novice on AX technologies.
- I haven't configure the retail channel (but I can ask our client for changes, or get details about configuration).

Here's my code :

void CreateCustomer()
{
    long channelId = ***;
    string connectionString = "Server=***;Database=***;User Id=***;Password=***";

    var configSection = CommerceRuntimeConfigurationManager.GetConfigurationSection("commerceRuntime");
    var commercePrincipal = new CommercePrincipal(new CommerceIdentity(channelId, Enumerable.Empty<string>()));
    var runtime = CommerceRuntime.Create(new CommerceRuntimeConfiguration(configSection, connectionString, true), commercePrincipal);
    
    CustomerManager customerManager = CustomerManager.Create(runtime);
    
    Customer newCustomer = new Customer();
    newCustomer.AccountNumber = "an unique account num";
    newCustomer.PriceGroup = "a price group";
    newCustomer.CustomerGroup = "a customer group";
    newCustomer.Name = "name of customer";
    // etc...
    
    customerManager.CreateCustomer(newCustomer); // throw exception, see below
}

The exception I get is this :

--- CommunicationException ---
An unhandled exception of type 'Microsoft.Dynamics.Commerce.Runtime.CommunicationException' occurred in Microsoft.Dynamics.Commerce.Runtime.Workflow.dll
Additional information: Exception while calling invoke method NewCustomer:
No elements matching the key 'WSHttpBinding' were found in the configuration element collection.

And the StackTrace :

System.ServiceModel.Configuration.ServiceModelConfigurationElementCollection`1.get_Item(Object key)
System.ServiceModel.WSHttpBinding.ApplyConfiguration(String configurationName)
System.ServiceModel.WSHttpBinding..ctor(String configName)
Microsoft.Dynamics.Commerce.Runtime.TransactionService.TransactionServiceClientFactory.CreateBinding()
Microsoft.Dynamics.Commerce.Runtime.TransactionService.TransactionServiceClientFactory.DoRefresh()
Microsoft.Dynamics.Commerce.Runtime.TransactionService.TransactionServiceClientFactory.get_ChannelFactory()
Microsoft.Dynamics.Commerce.Runtime.TransactionService.TransactionServiceClientFactory.CreateTransactionServiceClient()
Microsoft.Dynamics.Commerce.Runtime.TransactionService.TransactionServiceClient.GetResponseFromMethod(String methodName, Object[] parameterList, Boolean useExtensionMethod)


It sounds like a WCF error, but as the Dynamics Retail Server is a black box to me, I don't know how to configure the client side (in the app.config). Any idea ?

Last precision : the CustomerManager works on the other side, the method GetCustomer() for example.

Here's the app.config and the commerceRuntime.config (provided by CRT's SDK, no changes) :

<configuration>
  <configSections>
    <section name="commerceRuntime" type="Microsoft.Dynamics.Commerce.Runtime.Configuration.CommerceRuntimeSection, Microsoft.Dynamics.Commerce.Runtime.ConfigurationProviders, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
  </configSections>
  <commerceRuntime>
    <storage defaultOperatingUnitNumber="" />
    <query defaultPageSize="250" maxPageSize="5000" />
    <cache disableCaching="false" disableCacheUpdates="false" forceCacheLookupHostile="false" forceCacheLookupMiss="false" forceCacheLookupHit="false" />
    <composition>
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.Services" />
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.Services.Desktop, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.TransactionService, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.Workflow, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.DataServices, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.DataServices.SqlServer, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.DataAccess.SqlServer, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.Cache.MemoryCache, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
    </composition>
  </commerceRuntime>
</configuration>

<configuration>
  <commerceRuntime>
    <storage defaultOperatingUnitNumber="" />
    <query defaultPageSize="250" maxPageSize="5000" />
    <cache disableCaching="false" disableCacheUpdates="false" forceCacheLookupHostile="false" forceCacheLookupMiss="false" forceCacheLookupHit="false" />
    <composition>
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.Services" />
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.Services.Desktop, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.TransactionService, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.WorkflowFoundation, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.Workflow, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.DataServices, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.DataServices.SqlServer, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.DataAccess.SqlServer, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
      <add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.Cache.MemoryCache, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
    </composition>
  </commerceRuntime>
</configuration>

Any help would be appreciated !

Best regards,
Charles

*This post is locked for comments

  • Community Member Profile Picture
    on at
    RE: [AX 2012] The minimal way to create a customer in a retail DB with CRT and .NET

    I'm going to anwser my own question :

    After many attempts, I found a WCF client configuration who actually works, I'm not sure if all the infos are required though :

    <system.serviceModel>
        <bindings>
          <wsHttpBinding>
            <binding name="WSHttpBinding"
                     closeTimeout="00:01:00"
                     openTimeout="00:01:00"
                     receiveTimeout="00:10:00"
                     sendTimeout="00:01:00"
                     maxBufferPoolSize="10485760"
                     maxReceivedMessageSize="10485760"
                     textEncoding="utf-16"
                     messageEncoding="Text"
                     useDefaultWebProxy="true">
              <readerQuotas maxStringContentLength="10485760"
                            maxBytesPerRead="10485760" />
              <security mode="TransportWithMessageCredential">
                <transport clientCredentialType="None"
                           proxyCredentialType="None" />
                <message clientCredentialType="UserName"
                         algorithmSuite="Default"
                         negotiateServiceCredential="true" />
              </security>
            </binding>
          </wsHttpBinding>
        </bindings>
      </system.serviceModel>

    After this step, my code above works (a customer have been created both in the retail DB and the AX primary DB).

    Nevertheless, an exception is thrown at the end of the process :

    "The column VALIDTO cannot be NULL on DIRPERSONNAME"

    which doesnt make sense because :

    1 - If I check directly in the SQL table, the row exists and the column is fill with the value "2154-12-31 23:59:59.000"

    2 - The Visual Studio debugger indicates that the error happens in stored procedure "CREATEUPDATECUSTOMER", who proceeds this way :

    SET @dtt_MaxAxDate = crt.GETMAXAXDATE(); -- Never expires

    INSERT
    ( /* ... */, VALIDTO )
    VALUES
    ( /* ... */, @dtt_MaxAxDate );

     

    Any idea on how avoid this error ?

    Thanks & regards,

    Charles

  • Verified answer
    Community Member Profile Picture
    on at
    RE: [AX 2012] The minimal way to create a customer in a retail DB with CRT and .NET

    I'm going to anwser my own post again, and close the topic :

    There is a serious mystake in the SQL schema of the retail database :

    The value "2154-12-31 23:59:59.000" is mentionned twice, and the cast on datetime is not working on this string.

    I had to subtitute with "2154-12-31T23:59:59.000", recreate the function "GETMAXAXDATE" and one stored procedure, and now it's working.

    Not sure though if the error comes from Microsoft or the DBA who creates the database I use...

    In the first case, it's weird that I'm the first one to check this error ! (nobody is using the retail / commerce runtime ?)

    Charles

  • Community Member Profile Picture
    on at
    RE: [AX 2012] The minimal way to create a customer in a retail DB with CRT and .NET

    Hi Charles,

    Thanks for sharing this information but when I run this, I get following error:

    Value cannot be null.
    Parameter name: RTSIdentityProvider

    Can you suggest me what I am doing wrong here?

    Best Regards,

    Vivek

  • Community Member Profile Picture
    on at
    RE: The minimal way to create a customer in a retail DB with CRT and .NET

    Hi Vivek,

    It's will not be the answer you hope, but at least you will not wait !

    I never had the problem you have. I actually quitted my job 2 months atfer I created this topic. And Microsoft Dynamics was one of the reason... in two words : NEVER AGAIN.

    I wish you will find your answer but most important : I wish you will work on a better project soon !

    Note : for what it's worth, I know that my former company has stopped using the commerce runtime. I'm guessing, at some point, they had too much unresolvable issues with it.

    Charles

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans