.NET tutorial - Consume API XML WebService

A step-by-step instruction for consuming LemonWay API (XML) using C# in Microsoft Visual Studio.

1. Generate WebService stubs by Adding Service Reference

  1. In the Solution Explorer, right-click on "References" of your project then choose "Add Service Reference...".


  2. Fill your directkit URL, name it in "Namespace".


    You can click on OK to generate the artifacts and start to consume the Web Service immediately but we recommended to do one more step before clicking on OK.

  3. Click on "Advanced..." in the previous dialog, check on "Always generate message contracts".

2. Use the generated artifacts to call the Web Service

Now you can consume LemonWay API

var request = new LemonWayAPI.GetWalletDetailsRequest {
	wallet      = "sc";
	wlLogin     = "dupont";
	wlPass      = "********";
	language    = "fr";
	version     = "1.9";
	walletIp    = "127.0.0.1";
	walletUa    = "cs";
};

var soapClient = new LemonWayAPI.Service_mb_xmlSoapClient();
var response = soapClient.GetWalletDetails(request);

var result = response.GetWalletDetailsResult;

if (result.E != null) { //case error
	var err = result.E;
	Console.WriteLine(err.Code + " | " + err.Error + " | " + err.Msg);
}
else { // case ok: print the wallet information
	Console.WriteLine("Wallet status: " + result.WALLET.STATUS);
}

See also the GetWalletDetails service

Update Service Reference

After Adding the service references (Step 1) you should observe the following changes in your project

  • A new block is added in your app.config It is the configuration of the WebService endpoint. When you deploy your application
    • You must to deploy this new configuration,
    • OR you must to define the endpoint programaticly in your code.
  • A new folder Service References is created, which contains generated stubs. There might be many files in this folder but you should pay attention to only 2 files
    • Reference.cs contains all the classes (services wrapper, input, output structure) which is generated from the Service Description
    • Reference.svcmap contains service configs, metadata. You must to "commit" this file with your sources, so that other team members could re-generate the above Reference.cs or update the service reference as following

Your project uses classes in Reference.cs. so it is a good idea to commit also your Reference.cs to the code repository so that your project will compile on your Build System (Jenkins, TeamCity...)

LemonWay will regulary update the API, you should Update Service Reference and re-compile / re-deploy your application regulary in order to benefit new features in the API. LemonWay will try the best to keep backward compatibility, so we recommend you to upgrade the refrence to our service as frequently as you could..