> For the complete documentation index, see [llms.txt](https://developer.ecall-messaging.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.ecall-messaging.com/api-references/soap-webservice/code-examples.md).

# Code examples

### Setup and dependencies

{% tabs %}
{% tab title="C# (.NET)" %}
Add a WSDL reference in Visual Studio:

1. Right-click the project.
2. Select **Add Connected Service** or **Add Web Reference**.
3. Enter `https://soap.ecall.ch/eCall.asmx`.
4. Set a namespace, for example `eCallService`.

You can also use `dotnet-svcutil`:

```bash
dotnet tool install --global dotnet-svcutil
dotnet-svcutil https://soap.ecall.ch/eCall.asmx?WSDL
```

{% endtab %}

{% tab title="Python" %}

```bash
pip install zeep
```

{% endtab %}

{% tab title="Java" %}
Generate JAX-WS client code:

```bash
wsimport -keep -p com.ecall.soap https://soap.ecall.ch/eCall.asmx?WSDL
```

Or add the runtime dependency:

```xml
<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>4.0.0</version>
</dependency>
```

{% endtab %}
{% endtabs %}

### Send SMS — `SendSMSBasic`

{% tabs %}
{% tab title="C# (.NET)" %}

```csharp
using eCallService;

var client = new eCallSoapClient(
    eCallSoapClient.EndpointConfiguration.eCallSoap12
);

var request = new SendSMSBasicRequest
{
    AccountName     = "johnsmith",
    AccountPassword = "secretpassword",
    Address         = "0041791234567",
    Message         = "Hello from eCall!",
    JobID           = "SMS-001"
};

var response = await client.SendSMSBasicAsync(request);

if (response.ResponseCode == 0)
{
    Console.WriteLine("SMS successfully submitted.");
}
else
{
    Console.WriteLine($"Error {response.ResponseCode}: {response.ResponseText}");
}
```

{% endtab %}

{% tab title="Python" %}

```python
from zeep import Client
from zeep.transports import Transport
import requests

session = requests.Session()
transport = Transport(session=session, timeout=30)

client = Client(
    wsdl="https://soap.ecall.ch/eCall.asmx?WSDL",
    transport=transport
)

service = client.bind("eCall", "eCallSoap12")

response = service.SendSMSBasic(
    AccountName="johnsmith",
    AccountPassword="secretpassword",
    Address="0041791234567",
    Message="Hello from eCall!",
    JobID="SMS-001"
)

if response.ResponseCode == 0:
    print("SMS successfully submitted.")
else:
    print(f"Error {response.ResponseCode}: {response.ResponseText}")
```

{% endtab %}

{% tab title="Java" %}

```java
import com.ecall.soap.*;

ECall service = new ECall();
ECallSoap port = service.getECallSoap12();

SendSMSBasicRequest request = new SendSMSBasicRequest();
request.setAccountName("johnsmith");
request.setAccountPassword("secretpassword");
request.setAddress("0041791234567");
request.setMessage("Hello from eCall!");
request.setJobID("SMS-001");

SendSMSBasicResponse response = port.sendSMSBasic(request);

if (response.getResponseCode() == 0) {
    System.out.println("SMS successfully submitted.");
} else {
    System.out.printf("Error %d: %s%n",
        response.getResponseCode(),
        response.getResponseText());
}
```

{% endtab %}
{% endtabs %}

### Send fax with attachment — `SendFax`

{% tabs %}
{% tab title="C# (.NET)" %}

```csharp
using System.IO;
using eCallService;

var client = new eCallSoapClient(
    eCallSoapClient.EndpointConfiguration.eCallSoap12
);

byte[] pdfBytes  = File.ReadAllBytes("document.pdf");
string pdfBase64 = Convert.ToBase64String(pdfBytes);

var request = new SendFaxRequest
{
    AccountName     = "johnsmith",
    AccountPassword = "secretpassword",
    Address         = "0041441234567",
    Message         = "Please find the document attached.",
    Subject         = "Test fax",
    JobID           = "FAX-001",
    FaxHeaderID     = "+41 44 123 45 67",
    FaxHeaderInfo   = "F24 Schweiz AG",
    TokenFields     = "MaxRetries;=3;:RetriesTimeIntervallInMin;=10",
    Attachments     = new[]
    {
        new Attachment { FileName = "document.pdf", FileContent = pdfBase64 }
    }
};

var response = await client.SendFaxAsync(request);
Console.WriteLine(response.ResponseCode == 0 ? "Fax submitted." : $"Error: {response.ResponseText}");
```

{% endtab %}

{% tab title="Python" %}

```python
import base64
from zeep import Client
from zeep.transports import Transport
import requests

session = requests.Session()
client = Client(
    wsdl="https://soap.ecall.ch/eCall.asmx?WSDL",
    transport=Transport(session=session, timeout=30)
)
service = client.bind("eCall", "eCallSoap12")

with open("document.pdf", "rb") as f:
    pdf_base64 = base64.b64encode(f.read()).decode("utf-8")

Attachment = client.get_type("ns0:Attachment")
attachment = Attachment(FileName="document.pdf", FileContent=pdf_base64)

response = service.SendFax(
    AccountName="johnsmith",
    AccountPassword="secretpassword",
    Address="0041441234567",
    Message="Please find the document attached.",
    Subject="Test fax",
    JobID="FAX-001",
    FaxHeaderID="+41 44 123 45 67",
    FaxHeaderInfo="F24 Schweiz AG",
    TokenFields="MaxRetries;=3;:RetriesTimeIntervallInMin;=10",
    Attachments=[attachment]
)

print("OK" if response.ResponseCode == 0 else f"Error: {response.ResponseText}")
```

{% endtab %}

{% tab title="Java" %}

```java
import java.nio.file.*;
import java.util.Base64;
import com.ecall.soap.*;

ECall service = new ECall();
ECallSoap port = service.getECallSoap12();

byte[] pdfBytes = Files.readAllBytes(Path.of("document.pdf"));
String pdfBase64 = Base64.getEncoder().encodeToString(pdfBytes);

Attachment attachment = new Attachment();
attachment.setFileName("document.pdf");
attachment.setFileContent(pdfBase64);

SendFaxRequest request = new SendFaxRequest();
request.setAccountName("johnsmith");
request.setAccountPassword("secretpassword");
request.setAddress("0041441234567");
request.setMessage("Please find the document attached.");
request.setSubject("Test fax");
request.setJobID("FAX-001");
request.setFaxHeaderID("+41 44 123 45 67");
request.setFaxHeaderInfo("F24 Schweiz AG");
request.setTokenFields("MaxRetries;=3;:RetriesTimeIntervallInMin;=10");
request.getAttachments().add(attachment);

SendFaxResponse response = port.sendFax(request);
System.out.println(response.getResponseCode() == 0 ? "Fax submitted." : "Error: " + response.getResponseText());
```

{% endtab %}
{% endtabs %}

### Send voice message — `SendVoiceBasic`

{% tabs %}
{% tab title="C# (.NET)" %}

```csharp
var request = new SendVoiceBasicRequest
{
    AccountName      = "johnsmith",
    AccountPassword  = "secretpassword",
    Address          = "0041791234567",
    Message          = "Attention! This is a test message from eCall.",
    MessageLanguage  = "EN",
    JobID            = "VOICE-001"
};

var response = await client.SendVoiceBasicAsync(request);
```

{% endtab %}

{% tab title="Python" %}

```python
response = service.SendVoiceBasic(
    AccountName="johnsmith",
    AccountPassword="secretpassword",
    Address="0041791234567",
    Message="Attention! This is a test message from eCall.",
    MessageLanguage="EN",
    JobID="VOICE-001"
)
```

{% endtab %}

{% tab title="Java" %}

```java
SendVoiceBasicRequest request = new SendVoiceBasicRequest();
request.setAccountName("johnsmith");
request.setAccountPassword("secretpassword");
request.setAddress("0041791234567");
request.setMessage("Attention! This is a test message from eCall.");
request.setMessageLanguage("EN");
request.setJobID("VOICE-001");

SendVoiceBasicResponse response = port.sendVoiceBasic(request);
```

{% endtab %}
{% endtabs %}

### Query send status — `GetStateBasic`

{% tabs %}
{% tab title="C# (.NET)" %}

```csharp
var request = new GetStateBasicRequest
{
    AccountName     = "johnsmith",
    AccountPassword = "secretpassword",
    JobID           = "SMS-001",
    Address         = "0041791234567"
};

var response = await client.GetStateBasicAsync(request);

if (response.ResponseCode == 0)
{
    var job = response.JobResponse;
    Console.WriteLine($"Status:    {job.SendState}");
    Console.WriteLine($"Completed: {job.FinishDate}");
    Console.WriteLine($"Credits:   {job.PointsUsed}");
}
```

{% endtab %}

{% tab title="Python" %}

```python
response = service.GetStateBasic(
    AccountName="johnsmith",
    AccountPassword="secretpassword",
    JobID="SMS-001",
    Address="0041791234567"
)

if response.ResponseCode == 0:
    job = response.JobResponse
    print(f"Status:    {job.SendState}")
    print(f"Completed: {job.FinishDate}")
    print(f"Credits:   {job.PointsUsed}")
else:
    print(f"Error {response.ResponseCode}: {response.ResponseText}")
```

{% endtab %}

{% tab title="Java" %}

```java
GetStateBasicRequest request = new GetStateBasicRequest();
request.setAccountName("johnsmith");
request.setAccountPassword("secretpassword");
request.setJobID("SMS-001");
request.setAddress("0041791234567");

GetStateBasicResponse response = port.getStateBasic(request);

if (response.getResponseCode() == 0) {
    JobResponse job = response.getJobResponse();
    System.out.println("Status:    " + job.getSendState());
    System.out.println("Completed: " + job.getFinishDate());
    System.out.println("Credits:   " + job.getPointsUsed());
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.ecall-messaging.com/api-references/soap-webservice/code-examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
