Webservice
From Axaptapedia
Contents |
[edit] Description
A webservice is a software component that can be called using the standard internet protocolls. Webservices are based on XML protocolls: WSDL is used to describe the interface; SOAP is used to call the service and receive the response. Because the communication and interface description is XML based, webservices are technology neutral. Service Oriented Architecures (SOA) are built upon webservices. Webservices can be call synchronouse and asynchronouse. A synchronouse usage is like RMI where a method is called and the client is idle until response. For example online payment. Asynchronouse services are used for long term actions. The client only submits data to the service and doesn't wait for response. For example placing a sales order.
[edit] Types of nodes
The webservice infrastructure has 3 types of nodes:
- Registries are used to register a service so it can be found by consumers. The registry holds information about the service like Quality of Service, Provider, Description, Keywords etc. Registries either be public or private. Clients can query for services that fit their needs. Like the yello pages for software components. Most registries use UDDI
- Service Providers are hosting services and register them to registries. The provider is the owner of the service and has to keep it alive and the registry entries up to date.
- Service requesters query the service registries to find appropriate services. The registry provides the contact information (URL). In a SOA the requesters query the registries, exchange and arrange services automatically based on the business needs.
[edit] REST Webservice
The term webservice is almost a synonyum for XML/SOAP webservice. Just to mention, webservices are not limited to XML/SOAP. REST is a lightweight way to provide and use functionallity over the internet.
[edit] Call from Dynamics AX 3
Using Mantis WebService in Ax 3.0 via MSSOAP COM object
static void test_Mantis(Args _args) { // create an MSSOAP object COM ws = new COM('MSSOAP.SoapClient30'); Array priorities; COM item; int i; XMLSelection priority; str getValue(XMLSelection _selection, str _name) { int j; str id; str name; XMLElement element; for (j=0; j<_selection.length(); j++) { element = _selection.item(j); if (element.baseName() == _name) return element.text(); } } ; // init this object pointing it to WSDL of the Mantis web service ws.MSSoapInit("http://www.mantisbt.org/bugs/api/soap/mantisconnect.php?wsdl"); // enumerate priorities of tasks in the mantis bugtracker // user name and password are empty priorities = ws.mc_enum_priorities('',''); // output IDs and Names of all priorities for (i=1; i<=priorities.lastIndex(); i++) { priority = priorities.value(i); info(strFmt('%1: %2', getValue(priority, 'id'), getValue(priority, 'name'))); } }
[edit] Call from Dynamics AX 4
Using webservices inside Dynamics AX 4 is easy. You may use the command line tools to generate the proxy classes or Visual Studio.
1(a) Command Line Tools
- Create the proxy classes for your desired service. This can be done inside visual studio by adding a web reference or using the command line tool wsdl. The tool is located at C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin . The following call will create the proxy code for Microsoft Terraservice US, with namespace com.company.ax.web and write it to TerraServiceProxy.cs
wsdl /namespace:com.company.ax.web /out:TerraServiceProxy.cs http://terraserver.microsoft.net/terraservice.asmx?WSDL
- Create a public/private key pair using the sn tool
sn -k mykey.snk
- Compile the generated file to a dll and sign it with the generated key
csc /target:library /keyfile:mykey.snk TerraServiceProxy.cs
or 1(b) Visual Studio
- Start Visual Studio and create a new C# Library project
- In the project explorer add a new web reference
- Copy the URL in the text field. The assistant will download the WSDL file and parse it
- Accept or change the suggeste namespace. Visual Studio generates the proxy code for you
- Right click on the library project and open the properties window
- Go to the Signing tab. Activate the "Sign Assembly" checkbox. Open the dropdown an choose the "New" option. Provide a keyname like "mykey". It is not necessary to use a password. You may deactivate that option.
- Save and close the properties window
- Change the Build type from "Debug" to "Release" and build the solution
2 Register Assembly
- Copy the dll to the Client/Bin directory. If you want to use the assembly on the server, copy the dll also in the Server/bin directory.
- Use the gacutil tool to register the dll in the global assembly cache
gacutil /i TerraServiceProxy.dll
- Start Dynamics AX, open the AOT and add the Assembly to the references node
3 Use the Service
Unfortunately X++ has no support for namespace, so you have to use the full qualified name.
Proxy.net.microsoft.terraserver.TerraService service = new Proxy.net.microsoft.terraserver.TerraService(); Proxy.net.microsoft.terraserver.Place place = new Proxy.net.microsoft.terraserver.Place(); Proxy.net.microsoft.terraserver.LonLatPt point; Proxy.net.microsoft.terraserver.PlaceFacts facts; System.String center; real lon; real lat; ; /* where is fresno ? */ place.set_City("Fresno"); place.set_State("California"); place.set_Country("United States"); facts = service.GetPlaceFacts(place); point = facts.get_Center(); lon = point.get_Lon(); lat = point.get_Lat(); info( strfmt("Fresno is located at Lon:%1 Lat:%2",lon,lat) );



