Consume external web services
You can consume web services by adding new class libraries. In Microsoft Dynamics AX 2012, 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++.
Note that the web service URL in this sample is fictional. There is no known web service at http://www.contoso.net/stockquote.asmx. To make this code work you will need to adapt it to your specific web service.
Create a new Class Library project in Visual Studio, and name it ExternalServiceLibrary.csproj.
In the Visual Studio project, add a service reference to the external web service:
http://www.contoso.net/stockquote.asmx
.Create a new static class, and wrap the StockQuote service operation as shown in the following example.
public static string GetQuote(string s) { var binding = new System.ServiceModel.BasicHttpBinding(); var endpointAddress = new EndpointAddress("http://www.contoso.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"); }
Build the project. The binary ExternalServiceLibrary.dll is created.
Create a new Dynamics project in Visual Studio.
Add ExternalServiceLibrary.dll as a reference.
In the X++ class, you can use the external web services that were referenced in ExternalServiceLibrary.dll.
public static void main(Args _args) { info(ServiceLibrary.StockQuoteClass::GetQuote("MSFT")); }
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈