I have been working with the dotnet interop and consuming soap web services. I wrote about a dotnet interop based way to communicate with soap web services in a previous blog but now I want to demonstrate another way that requires just a few lines of code.
I would like to find a web service that is open so everyone can do their own testing. I found a web service that will look up a country by an IP address.
The first step is to start Microsoft Visual Studio and create a new project. The language that you choose is not important.
I delete Class1.cs. Then go to Project menu and Add Service Reference. Click Advanced… and Add Web Reference… Look in my previous blog for more details.
I paste the web service URL in to Visual Studio and select a name for the web reference.
I go to Project and GeoIPService Properties to make sure that I am using .NET Framework 3.5 and I choose to create my own key to sign the class. I also like to add details to the Assembly Information…
I go to Signing and create a new key file with my own password.
Then I save the project and select Build and Build GeoIPService. In the solution folder I will now find the GeoIPService.dll file. This file I copy to my Classic Client Add-ins folder. I start the Classic Client and create a new Codeunit. I will then add a dotnet global variable with my new class. I create a variable both for GeoIPService and for GeoIP.
I the need to choose if I would like the service to be run on the client or on the server. If I choose to run on the client then I need to copy the class file to Role Tailored Client Add-ins folder for every user. If I choose to run on server I copy the class file to the service Add-ins folder. I selected to run on server since I do not have to supply my domain user name or any certificates to the service.
The code in the Codeunit is as follows
GeoIPService := GeoIPService.GeoIPService;
GeoIPService.Url := ‘http://www.webservicex.net/geoipservice.asmx’;
GeoIP := GeoIPService.GetGeoIP(‘220.127.116.11’);
‘Return Code: %1\IP Address %2\Country Name: %3\Country Code: %4’,
I then start the codeunit in my Role Tailored Client with the Run Object Page that Microsoft supplied in their blog.
Attached is the codeunit, the class library and the Run Object Page from Microsoft.