Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

Test the XML using .NET for AIF webservice (NETTcp)

Posted on by 70

Hello Team,

I have one XML which I would like to pass and test into the AIF webservice in AX 2012. The AIF webservice is using (Net Tcp) adaptor.

My understanding is that I can not use Postman tool or SOAP UI as the hosting ins on (NET TCP) adaptor. So I am thinking to use the .NET code within my machine to pass the XML in AIF webservice.

Can anyone please provide a sample code where I can pass the XML to the webservice and also debug the data in AX side ?

Thanks.

  • Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: Test the XML using .NET for AIF webservice (NETTcp)

    Regarding SecurityNegotiationException, it would be better to discuss it in a WCF forum. If you want to discuss it here anyway, please tell us how you've configured transport security at both sides.

    Document services can be debugged - see Debugging in Microsoft Dynamics AX 2012 > Services in AX 2012 documentation.

    By the way, please always use Insert > Code (in the rich formatting view) to paste source code. It'll make it easier to read and work with.

  • Anudeep1806 Profile Picture
    Anudeep1806 70 on at
    RE: Test the XML using .NET for AIF webservice (NETTcp)

    Hello Martin,

    In our enterprise, we have a web based application and also has Dynamics AX 2012 R3 CU8.

    In web application, once there is one SO created, web application sends that information to Dynamics AX 2012 R3 by passing the XML to the AIF webservice in AX 2012 R3.

    Both web application and Dynamics AX 2012 R3 are in the same domain. The AIF web service is hosted on .NET adaptor  in AX 2012.

    Now our web team has provided the XML which they normally pass to Dynamics. We are trying to pass and test that XML using the .NET code.

    Below is the screen shot of the AIF adaptor and the corresponding service. 

    pastedimage1653955247471v1.png

    Sales Order group:

    pastedimage1653955318767v2.png

    Sales order service:

    pastedimage1653955346813v3.png

    Below is the sample code which we are trying to create the Sales order by passing some sample hardcoded values (as we do not have any code how to pass the XML in to AIF webservice via .NET).

    /*using System;

    namespace TestAIFSOService
    {
    class Program
    {
    static void Main(string[] args)
    {
    Console.WriteLine("Hello World!");
    }
    }
    }*/

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using TestAIFSOService;
    using ServiceReference2;
    using System.Threading.Tasks;

    namespace TestAIFSOService
    {
    class Program
    {
    static void Main(string[] args)
    {// Instantiate an instance of the service client class.
    SalesOrderServiceClient proxy = new SalesOrderServiceClient();

    // Create an instance of the document class.
    AxdSalesOrder salesOrder = new AxdSalesOrder();

    // Create instances of the entities that are used in the service and
    // set the needed fields on those entities.
    ServiceReference2.AxdEntity_SalesTable salesTable = new AxdEntity_SalesTable();
    salesTable.CurrencyCode = "USD";
    salesTable.CustAccount = "C846456";
    salesTable.ReceiptDateRequested = Convert.ToDateTime("4/21/2020");
    salesTable.Payment = "PP";

    AxdEntityKey_LogisticsPostalAddress LPA = new AxdEntityKey_LogisticsPostalAddress();
    LPA.Location_LocationId = "5637282089";

    AxdExtType_EffectiveDateTime date = new AxdExtType_EffectiveDateTime();
    date.timezone = AxdEnum_Timezone.GMT_COORDINATEDUNIVERSALTIME;
    DateTime dateValue = new DateTime(2015, 4, 29, 14, 10, 53, 001, DateTimeKind.Utc);

    date.timezoneSpecified = false;
    date.localDateTimeSpecified = false;
    date.Value = dateValue;
    LPA.ValidFrom = date;
    salesTable.DeliveryPostalAddress = LPA;

    AxdEntity_SalesLine salesLine = new AxdEntity_SalesLine();
    salesLine.ItemId = "10-009";
    salesLine.SalesQty = 9;
    salesLine.SalesUnit = "ea";

    CallContext callContext = new CallContext();
    //GG-Added the code
    // SalesOrderServiceClient client = new SalesOrderServiceClient();

    //GG-End the code
    callContext.Language = "en-us";
    callContext.Company = "HYD"; //"KTEC";
    //callContext.LogonAsUser
    salesOrder.SalesTable = new AxdEntity_SalesTable[1] { salesTable };
    salesTable.SalesLine = new AxdEntity_SalesLine[1] { salesLine };
    //
    proxy.ChannelFactory.Credentials.UserName.UserName = "mydomain\\myusername";
    proxy.ChannelFactory.Credentials.UserName.Password = "mypassword";


    try
    {
    // Call the create method on the service passing in the document.
    EntityKey[] returnedSalesOrderEntityKey = proxy.create(callContext, salesOrder);
    // The create method returns an EntityKey which contains the ID of the sales order.
    EntityKey returnedSalesOrder = (EntityKey)returnedSalesOrderEntityKey.GetValue(0);
    Console.WriteLine("The sales order created has a Sales ID of " + returnedSalesOrder.KeyData[0].Value);
    Console.ReadLine();
    }
    catch (Exception e)
    {
    Console.WriteLine(e.ToString());
    Console.ReadLine();
    }

    }
    }
    }

    and getting the below error message, 

    + e {"Transport security negotiation failed due to an underlying IO error: Unable to read data from the transport connection: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:10:00'..."} System.Exception {System.ServiceModel.Security.SecurityNegotiationException}

    but our end goal is to pass the XML in .NET code and create a Sales order in AX (Also if we can debug the code in AX, that would also be very helpful).

    Regards

  • Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: Test the XML using .NET for AIF webservice (NETTcp)

    Please tell us more about your scenario and your problem.

    Do you have a service to call? If not, you need to make it first. For example, maybe you want to create a custom service accepting a string and parse XML by yourself there. You may also want to reconsider the idea of passing your XML to F&O. Maybe you want to transform it to a format expected by an existing document service. It will help if you explain your busiuness scenario, instesad of diving into implementation details without providing any context.

    If you have no idea about how consume SOAP web services in Visual Studio, look at Walkthrough: Exchanging documents by using the NetTcp adapter, for example. You can find more resource on the internet, of course, with pictures and everything.

    By the way, I moved your thread from the Finance forum here to the AX forum. Please use this forum for questions about AX 2012.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans