Creating a Client

Creating a fax client.

To create a new fax client, simply instantiate a new EtherFaxClient class and pass your api-key or account, username, and password information as parameters.

In this first example, the EtherFaxClient is created using an api-key and the FaxAccount information is returned to the caller. Note that all EtherFaxClient methods support the await keyword and may be executed asynchronously.

📘

Asynchronous Programming

C# has a language-level asynchronous programming model which allows for easily writing asynchronous code without having to juggle callbacks or conform to a library which supports asynchrony. It follows what is known as the Task-based Asynchronous Pattern (TAP).

// create client with api-key
var client = new EtherFaxClient("api_key");

// get account information
var account = client.GetFaxAccount();
Console.WriteLine("Account name: " + account.Name);

If you do not wish to use an api-key, the username/password constructor may be used.

var client = new EtherFaxClient("efax-0000-0000/my_user_name", "my_password");

USING A PROXY

A new feature introduced in the EtherFax.Client package is support for the HttpClientHandler, allowing the developer to specify a WebProxy or other features of this class. The client credentials should be set after the EtherFaxClient and HttpClientHandler have been created.

// create proxy handler
var handler = new HttpClientHandler()
{
	Proxy = new WebProxy("http://127.0.0.1:8888"),
	UseProxy = true,
};

// create client with handler
client = new EtherFaxClient(handler);
client.SetCredentials("api_key");

// display account information
var account = client.GetFaxAccount();
Console.WriteLine("Account name: " + account.Name);

What’s Next