Class MicroVPNService
MicroVPNService is the dependency service that provides APIs to the MAM SDK for micro VPN tunneling. The MicroVPNService class provides a platform-specific implementation to invoke native platform functionality from shared code.
Sample code reference for XAML binding class to call MicroVPNService.cs dependency service is as follows:
public partial class MainPage : ContentPage, IStartTunnelCallback
{
public MainPage()
{
InitializeComponent();
urlEntry.Text = "http://mycompanyinternalwebsite.com";
IMicroVPNService service = DependencyService.Get<IMicroVPNService>();
service.Init();
}
void OnStartTunnel(object sender, EventArgs args)
{
activityIndicator.IsRunning = true;
IMicroVPNService service = DependencyService.Get<IMicroVPNService>();
service.StartTunnel(this);
}
public void OnSuccess()
{
activityIndicator.IsRunning = false;
}
public void OnError(StartTunnelError error)
{
activityIndicator.IsRunning = false;
DisplayAlert("Error", error.ToString(), "OK");
}
void OnStopTunnel(object sender, EventArgs args)
{
IMicroVPNService service = DependencyService.Get<IMicroVPNService>();
service.StopTunnel();
}
void OnCheckTunnel(object sender, EventArgs args)
{
IMicroVPNService service = DependencyService.Get<IMicroVPNService>();
bool isRunning = service.IsNetworkTunnelRunning();
DisplayAlert("Info", isRunning ? "Tunnel is started" : "Tunnel is stopped", "OK");
}
async void OnWebView(object sender, EventArgs args)
{
activityIndicator.IsRunning = false;
await Navigation.PushAsync(new WebViewPage(urlEntry.Text));
}
async void OnHttpClient(object sender, EventArgs args)
{
activityIndicator.IsRunning = true;
try
{
IMicroVPNService service = DependencyService.Get<IMicroVPNService>();
HttpClient httpClient = service.CreateHttpClient();
var result = await httpClient.GetStringAsync(urlEntry.Text);
await DisplayAlert("HttpClient", result, "OK");
}
catch (Exception ex)
{
await DisplayAlert("Error", ex.Message, "OK");
}
finally
{
activityIndicator.IsRunning = false;
}
}
}
<!--NeedCopy-->
Inheritance
-> System.Object
-> MicroVPNService
Implements
IMicroVPNService
Namespace: Com.Citrix.Mvpn.Api.Droid
Assembly: MvpnSdkFormsLibrary.dll
Syntax:
public class MicroVPNService : Object, IMicroVPNService
<!--NeedCopy-->
Constructors
MicroVPNService()
Declaration:
public MicroVPNService()
<!--NeedCopy-->
Methods
CreateHttpClient()
This method creates a HttpClient object that is enabled for micro VPN tunneling. Sample code:
async void OnHttpClient()
{
try
{
IMicroVPNService service = DependencyService.Get<IMicroVPNService>();
HttpClient httpClient = service.CreateHttpClient();
var result = await httpClient.GetStringAsync("http://mycompanyinternalwebsite.com");
await DisplayAlert("HttpClient", result, "OK");
}
catch (Exception ex)
{
await DisplayAlert("Error", ex.Message, "OK");
}
}
<!--NeedCopy-->
Declaration:
public HttpClient CreateHttpClient()
<!--NeedCopy-->
Returns:
Type | Description |
---|---|
System.Net.Http.HttpClient | Returns a HttpClient object enabled for micro VPN tunneling. |
Init()
This method is used to initialize the micro VPN tunnel. Sample code:
IMicroVPNService service = DependencyService.Get<IMicroVPNService>();
service.Init();
<!--NeedCopy-->
Declaration:
public void Init()
<!--NeedCopy-->
IsNetworkTunnelRunning()
This method returns the status of the tunnel. If the tunnel is running, it returns true. Otherwise, it returns false. Sample code:
void OnCheckTunnelStatus()
{
IMicroVPNService service = DependencyService.Get<IMicroVPNService>();
bool isRunning = service.IsNetworkTunnelRunning();
DisplayAlert("Info", isRunning ? "Tunnel is started" : "Tunnel is stopped", "OK");
}
<!--NeedCopy-->
Declaration:
public bool IsNetworkTunnelRunning()
<!--NeedCopy-->
Returns:
Type | Description |
---|---|
System.Boolean | Returns the boolean status of the tunnel - true or false. |
StartTunnel(IStartTunnelCallback)
This method must be called to start the micro VPN tunnel. This is an asynchronous method call that returns the results through a callback provided as an input parameter. Sample code:
public partial class MyClass : IStartTunnelCallback
{
void OnStartTunnel()
{
activityIndicator.IsRunning = true;
IMicroVPNService service = DependencyService.Get<IMicroVPNService>();
service.StartTunnel(this);
}
public void OnSuccess()
{
activityIndicator.IsRunning = false;
DisplayAlert("Success", "Tunnel Started Successfully", "OK");
}
public void OnError(StartTunnelError error)
{
activityIndicator.IsRunning = false;
DisplayAlert("Error", error.ToString(), "OK");
}
}
<!--NeedCopy-->
Declaration:
public void StartTunnel(IStartTunnelCallback callback)
<!--NeedCopy-->
Parameters:
Type | Name | Description |
---|---|---|
IStartTunnelCallback |
callback | StartTunnel() method is an asynchronous call. Once the tunnel is started successfully, the results are returned through this callback. |
StopTunnel()
This method can be called to stop the micro VPN tunnel. Sample code:
void OnStopTunnel()
{
IMicroVPNService service = DependencyService.Get<IMicroVPNService>();
service.StopTunnel();
}
<!--NeedCopy-->
Declaration:
public void StopTunnel()
<!--NeedCopy-->
Implements
IMicroVPNService