Monday, September 25, 2017

Consuming external web services in Dynamics 365 for Finance and operations

Reference Source Link: https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/data-entities/services-home-page 

Consuming external web services

In previous versions, you could consume web services from X++ code by adding Microsoft Visual Studio projects as a reference and by using Aif::CreateServiceClient. This scenario is supported, but the steps have changed. Application Integration Framework (AIF) is no longer supported. The following steps show how to consume an external StockQuote service from X++.
  1. Create a new Class Library project in Visual Studio, and name it ExternalServiceLibrary.csproj.
  2. In the Visual Studio project, add a service reference to the external web service: http://www.webservicex.net/stockquote.asmx
  3. Create a new static class, and wrap the StockQuote service operation as shown in the following example.
  4.       public static string GetQuote(string s)
            {
                var binding = new System.ServiceModel.BasicHttpBinding();
                var endpointAddress = new EndpointAddress("http://www.webservicex.net/stockquote.asmx");
                ServiceLibrary.QuoteReference.StockQuoteSoapClient client = new ServiceLibrary.QuoteReference.StockQuoteSoapClient(binding, endpointAddress);
    
                //GetQuote is the operation on the StockQuote service
                return client.GetQuote("MSFT");
            }
  5. Build the project. The binary ExternalServiceLibrary.dll is created.
  6. Create a new Dynamics project in Visual Studio.
  7. Add ExternalServiceLibrary.dll as a reference.
  8. In the X++ class, you can use the external web services that were referenced in ExternalesrviceLibrary.dll.
  9.    public static void main(Args _args)
        {
            info(ServiceLibrary.StockQuoteClass::GetQuote("MSFT"));
        }


No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...