Creating an API Web Service Library

 

Introduction

Working with the e-conomic SOAP API from within a Visual Studio solution can at times be a waiting game when Visual Studio decides to update the web service reference. The reason for this is the size of the WSDL file. Visual Studio first has to download the WSDL file and then parse the XML.

By creating a service reference library you can remove these annoying service refreshes. The guide below explains how to create such a service.

 

Create a web service reference library (dll)

Follow the steps below to create your own reference library:

  • 1. Open Visual Studio.
  • 2. Create a new project of the Class Library type (by navigating to New Project -> Installed -> Templates -> Visual C# -> Windows Desktop).
  • 3. Choose Add Service Reference from the Project menu.
  • 4. In the Address field, enter https://api.e-conomic.com/secure/api1/EconomicWebService.asmx?wsdl and click Go.
  • 5. Under Services, choose the EconomicWebService, give it a namespace (e.g., EconApi) and click OK.

Note: The app.config configuration file will not be used by the class library project. You will need to add the settings in the generated configuration file to the app.config file for the client executable that will call the class library. But you can leave it in the solution and use it as a template for client apps.

 

Use in a client application

You can now use the web service library you've just created in a client application:

1. Open Visual Studio.
2. Create a new project of the Console Application type (by navigating to New Project -> Installed -> Templates -> Visual C# -> Windows Desktop).
3. Choose Add Reference from the Project menu.
4. Click Browse and add the web service library you created.
5. Choose Add Reference from the Project menu, and add System.ServiceModel under Assemblies.Framework.
6. Choose Add Reference from the Project menu, and add System.Runtime.Serialization under Assemblies.Framework.
7. Open web service library project app.config, and copy the tag contents to client app.config.
8. In Solution Explorer, right-click app.config and select Edit WCF configuration, and change the binding property AllowCookies to True under Bindings.

You can add the following code to test the client app, replacing token (AgreementGrantToken) and apptoken (AppSecretToken) with your own credentials:
var session = new EconWebService.EconApi.EconomicWebServiceSoapClient(); session.ConnectWithToken("AgreementGrantToken", "AppSecretToken"); var company = session.Company_Get(); Console.WriteLine(company.Number); session.Disconnect();


 

Update the service reference library with latest changes to the SOAP API

Here is how you update the reference library in case changes have been made to the SOAP API:
1. Open Visual Studio.
2. Open your service library project
3. Right-click on the service reference and select Update Service Reference.

Need help?

We are ready to help you with your API questions at api@e-conomic.com.
And if you have questions regarding apps, don't hesitate to contact apps@e-conomic.com.