The problem is that you've declared
WebServiceUrl
as a field. That means the initializer will run once, before the first access to the class, at which point your
FinalIPAddress
will be
null
.
When you update the
FinalIPAddress
property, it will have no effect on the value of the
WebServiceUrl
field.
Try changing
WebServiceUrl
to a property:
public static string WebServiceUrl
{
get { return System.Net.WebUtility.UrlEncode(FinalIPAddress); }
}
However, if you're trying to
call the API using that URL, rather than
passing the URL as a parameter to the API, then you'll need to remove the
UrlEncode
call:
public static string WebServiceUrl
{
get { return FinalIPAddress; }
}