Download presentation
Presentation is loading. Please wait.
1
Consuming Webservice in AX 2012
2
A web service is any piece of software that makes itself available over the internet and uses a standardized XML messaging system. XML is used to encode all communications to a web service. For example, a client invokes a web service by sending an XML message, then waits for a corresponding XML response. As all communication is in XML, web services are not tied to any one operating system or programming language--Java can talk with Perl; Windows applications can talk with Unix applications.
3
First, let us create a new Project in Visual Studio
First, let us create a new Project in Visual Studio. I'm want something easy and swift, so let's choose .Net 3.5 and ASP.Net Web Service Application. I'm naming the Project “CricketPlayerService”
4
Now just copy the code underneath and paste it in.
using System.Web; using System.Web.Services; namespace CricketPlayerService { public class PlayerInfo public string Name; public double Runs; public double Avg; public double SR; } /// <summary> /// Summary description for Service1 /// </summary> [WebService(Namespace = " [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService]
5
public class Service1 : System.Web.Services.WebService
{ [WebMethod] public List< PlayerInfo > SearchPlayer(String query) return new List<PlayerInfo> { new PlayerInfo{ Name = "Sachin Tendulkar", Runs = 18426, Avg = 44.83, SR = 86.24 }, Name = "Virender Sehwag", Runs = 8273, Avg = 35.06, SR =
6
new PlayerInfo{ Name = "M.S Dhoni", Runs = 9967, Avg = 51.38, SR = 88.41 }, Name = "Virat kohli", Runs = 9588, Avg = 58.11, SR = 92.15 } }; This is just a simple service that takes a string as input for query of players. It returns a list of 4 players. Now we need to change few things as shown below in IIS to run on Application pool that uses .Net 2 instead of .Net 4.
9
you can head back to Visual Studio and Publish your built solution
you can head back to Visual Studio and Publish your built solution. Right-click the project and choose Publish
11
You should be able to test the Web Service by opening a browser and navigating to it. Try loading and see what happens
12
If you click the SearchService-link you will get a description of that service and since it takes a simple string you can invoke the service from here. just press invoke and watch it open the result.
14
Create a new Visual Studio Project
Select .Net Framework 4 Select a template from Visual C# and Windows Select the Class Library as template. Give it a name like "DynamicsAXCricketService". Add a Service Reference and point to Add the project to the AOT Deploy as shown below
18
In order to get you started quickly, Note you need to make sure you have selected allow hot swapping of assembly in Server Configuration before you deploy
19
copy and paste the below job in Ax 2012 jobs and run see how you results are.
public static void CricketService(Args args) { DynamicsAXCricketService.ServiceReference1.Service1SoapClient wcfClient; DynamicsAXCricketService.ServiceReference1.PlayerInfo[] playerInfoArray; DynamicsAXCricketService.ServiceReference1.PlayerInfo playerInfo; System.ServiceModel.Description.ServiceEndpoint endPoint; System.ServiceModel.EndpointAddress endPointAddress; System.Exception ex; System.Type type; int i, numOfPlayer; str name; real Runs,Average,StrikeRate; try type = CLRInterop::getType('DynamicsAXCricketService.ServiceReference1.Service1SoapClient'); wcfClient = AifUtil::createServiceClient(type);
20
endPointAddress = new System. ServiceModel
endPointAddress = new System.ServiceModel.EndpointAddress(" endPoint = wcfClient.get_Endpoint(); endPoint.set_Address(endPointAddress); playerInfoArray = wcfClient.SearchPlayer("All"); numOfPlayer = playerInfoArray.get_Count(); for(i = 0; i < numOfPlayer; i++) { playerInfo = playerInfoArray.get_Item(i); name = playerInfo.get_Name(); Runs = playerInfo.get_Runs(); Average = playerInfo.get_Avg(); StrikeRate = playerInfo.get_SR(); info(strFmt("Name:%1 -Runs:%2 -Average:%3 -Strike Rate:%4", name, Runs, Average, StrikeRate)); }
21
catch(Exception::CLRError)
{ ex = CLRInterop::getLastException(); while(ex) info(CLRInterop::getAnyTypeForObject(ex.ToString())); ex = ex.get_InnerException(); } The Output when running this job is shown below.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.