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)

AX to AX Integration using AIF (net.tcp) within a Class Library (DLLs)

(0) ShareShare
ReportReport
Posted on by 201

We are trying to integrate 2 separate AX implementations using AIF

Steps:
1. Created AIF service in AX environment 1.


2. Wrote a .NET wrapper around the AIF, using a class library project type.


3. Deployed class library project in AOT of AX environment 2 and also added classlibrary.dll and classlibrary.dll.config in the Bin folder of 2nd environment and than added reference to dll in the AOT of environment 2


4. We finally wrote X++ job in AX environment 2 to call/consume the class library that was added in the AOT of AX environment 2.

Exception :
System.InvalidOperationException: Could not find default endpoint element that references contract 'AMSSVCSR.HREMPAIFService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    236,320 Most Valuable Professional on at
    RE: AX to AX Integration using AIF within a Class Library (DLLs)

    What exactly did you do with the class library projects? Your steps looks suspicious. You should create a class library in Visual Studio, add it to AOT (of environment 2) and configure it to be deployed automatically. You shouldn't manipulate any DLLs directly.

    The error means either that your config file is invalid (maybe because you did the previous step wrong), or it's loaded at all because you created the service client in X++ incorrectly (you have to use AifUtil::createServiceClient()).

  • ShaikhAtif Profile Picture
    201 on at
    RE: AX to AX Integration using AIF within a Class Library (DLLs)

    As you said, we created class library project in visual studio and added it to AOT of Environment 2 (using Deploy to AOT feature of AX visual studio tools).

    We haven't manipulated DLL directly. DLL of the .net class library is just placed in the bin folder of AX environment 2:

    C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin

    For sake of testing we have already successfully tested our class library DLL by calling it in the visual studio console based application and it works fine.

    But, when we try to call the DLL methods in a X++ job it returns 'default endpoint not found' exception.

    exception.png

  • Suggested answer
    Martin Dráb Profile Picture
    236,320 Most Valuable Professional on at
    RE: AX to AX Integration using AIF within a Class Library (DLLs)

    Putting DLL files to bin folder is exactly the unnecessary manipulation of DLL files I meant. AX can do deployment for you.

    Your call stack indeed suggests that you're creating the client incorrectly. As I said, you have to use AifUtil::createServiceClient().

  • ShaikhAtif Profile Picture
    201 on at
    RE: AX to AX Integration using AIF within a Class Library (DLLs)

    I tried to execute this code


    Note:  The provided URI scheme  'net.tcp'.


    static void testingNETCode(Args _args)
    {
        ABCSVCLIB.ABCSVCCL              ABCSVCCLDll;
        str s;
        System.Exception netExcepn;
        
        ABCSVCLIB.ABCSVCSR.HREMPAIFServiceClient  _client;
        ClrObject clientType;
        ABCSVCLIB.ABCSVCSR.HREMPAIFService postalService;
        System.ServiceModel.Description.ServiceEndpoint endPoint;
        System.ServiceModel.EndpointAddress endPointAddress;
        System.Exception exception;
        System.Type type;

        AMSSVCLIB.AMSSVCSR.HREMPAIFServiceGetHelloWorldRequest request;
        AMSSVCLIB.AMSSVCSR.HREMPAIFServiceGetHelloWorldResponse response;
        ;

        try
        {
            clientType = CLRInterop::getType('ABCSVCLIB.ABCSVCSR.HREMPAIFServiceClient');

            _client = AifUtil::createServiceClient(clientType);

            endPointAddress = new System.ServiceModel.EndpointAddress("7.91.205.21/.../HREMPAIFServiceGroup");

            endPoint = _client.get_Endpoint();

            endPoint.set_Address(endPointAddress);

             request = new AMSSVCLIB.AMSSVCSR.HREMPAIFServiceGetHelloWorldRequest();

            s = _client.getHelloWorld(request);

            info(strFmt('%1', s));
        }
        catch(Exception::CLRError)
        {
            // Get the .NET Type Exception
            exception = CLRInterop::getLastException();

            // Go through the inner exceptions
            while(exception)
            {
                // Print the exception to the infolog
                info(CLRInterop::getAnyTypeForObject(exception.ToString()));

                // Get the inner exception for more details
                exception = exception.get_InnerException();
            }
        }
    }


    2 Exception :

    >> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: The provided URI scheme 'http' is invalid; expected 'net.tcp'.

    >> System.ArgumentException: The provided URI scheme 'http' is invalid; expected 'net.tcp'.

  • Martin Dráb Profile Picture
    236,320 Most Valuable Professional on at
    RE: AX to AX Integration using AIF (net.tcp) within a Class Library (DLLs)

    Why are you overriding the address instead of using the configuration file?

    Your address isn't compatible with the rest of your configuration, because it's an HTTP address although you want to use net.tcp protocol.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: AX to AX Integration using AIF (net.tcp) within a Class Library (DLLs)

    Although this question is old now, but since i am working on the same scenario and have faced the exact same error, so i will submit the solution for anybody that could pass through the same issue in the future.

    The issue reason is: unfortunately app.config file of the C# project (class library in this case) is not seen inside AX, so all configurations including the endpoint address and binding contained in app.config is useless and you must configure your service client in the C# code before calling the client methods. So to accomplish that i will post here my answer i have already posted in other threads as follows:

    For those who work with AX 2012 AIF services and try to call their C# or VB project inside AX (x++) and suffer from such errors of "could not find default endpoint..."... or "no contract found..." ...

    Please go back to your visual studio (C#) project and add these following lines of code before defining your service client, then deploy the project and restart AX client and retry: Note, the example is for NetTcp adapter, you could easily use any other adapter instead according to your need.

    Uri Address = new Uri("net.tcp://your-server:Port>/DynamicsAx/Services/your-port-name");
    NetTcpBinding Binding = new NetTcpBinding();
    EndpointAddress EndPointAddr = new EndpointAddress(Address);
    SalesOrderServiceClient Client = new SalesOrderServiceClient(Binding, EndPointAddr);


  • Martin Dráb Profile Picture
    236,320 Most Valuable Professional on at
    RE: AX to AX Integration using AIF (net.tcp) within a Class Library (DLLs)

    Abdullah, you're wrong in thinking that you "must configure your service client in the C# code". If you want to load the configuration file, use AifUtil::CreateServiceClient(). You can find an example in Walkthrough: Calling an External Web Service from X++ [AX 2012].

  • Community Member Profile Picture
    on at
    RE: AX to AX Integration using AIF (net.tcp) within a Class Library (DLLs)

    Martin, i think you are totally right in the case of building the whole logic of consuming the service inside AX (x++). But what if you are calling the service client and consuming it's methods inside C# method,
    and then you call that C# method in x++ only to get the result?  

  • Martin Dráb Profile Picture
    236,320 Most Valuable Professional on at
    RE: AX to AX Integration using AIF (net.tcp) within a Class Library (DLLs)

    Of course, if you prefer doing it all in code, you can. I just corrected your statement claiming that it's necessary.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

#2
Guy Terry Profile Picture

Guy Terry 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans