Here is my solution;
The vpn connection is used to call webservices (soap) of the remote site.
To check every connection I created a derived class of SoapHttpClientProtocol from which webservice references are derived and edited all service references and drived them from new class NWSoapHttpClientProtocol.
C# code
public class NWSoapHttpClientProtocol : SoapHttpClientProtocol
{
protected new object[] Invoke(string methodName, object[] parameters)
{
try
{
return base.Invoke(methodName, parameters);
}
catch
{
RenewLocalIP();
return base.Invoke(methodName, parameters);
}
}
private void RenewLocalIP()
{
try
{
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.FileName = "ipconfig";
processStartInfo.Arguments = "/release ";
processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
Process process = Process.Start(processStartInfo);
process.WaitForExit();
processStartInfo = new ProcessStartInfo();
processStartInfo.FileName = "ipconfig";
processStartInfo.Arguments = "/renew";
processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process = Process.Start(processStartInfo);
process.WaitForExit();
EventLogger.Log(LogType.Information, MethodBase.GetCurrentMethod(), "Renewed Local IP");
}
catch (Exception ex)
{
while (ex.InnerException != null)
{
ex = ex.InnerException;
}
EventLogger.Log(LogType.Error, MethodBase.GetCurrentMethod(), ex.Message);
}
}
}
InvokeAsync methods of SoapHttpClientProtocol can also be implemented.