Open topic with navigation
Adding Support for Proxy Servers
Sometimes support for proxy servers is necessary, and it is possible to use
the System.Net.WebProxy class built into the .NET Framework (as of 2.0 and
later). As part of Microsoft's .NET Framework,
documentation
for this class is available from Microsoft, including additional details on
specifying credentials.
Using a specified proxy server
The excerpt of code below shows how the
ActivateOnline method, implemented in the
sample licensing class (ClientLicense,
for example), could be modified to support a proxy server when given a
specified host name and port.
- C#
- public bool ActivateOnline(Int32 licenseId, string password)
{
string licenseContent =
"";
com.softwarekey.Client.WebService.XmlActivationService.
XmlActivationService client =
new com.softwarekey.Client.WebService.XmlActivationService.
XmlActivationService();
client.
Url =
ConfigurationSettings.
AppSettings[
"XmlActivationServiceUrl"];
client.
Proxy =
new System.Net.
WebProxy(
"http://domain.com:80",
true);
if (!
this.
ActivateInstallationLicenseFile(
licenseId,
password,
client,
ref licenseContent))
return false;
return this.
SaveLicenseFile(
licenseContent);
}
- Visual Basic .NET
- Public Overloads Function ActivateOnline(ByVal licenseId As Int32, ByVal password As String) As Boolean
Dim licenseContent As String =
""Dim client As New com.softwarekey.Client.WebService.XmlActivationService.
XmlActivationService()
client.
Url =
ConfigurationSettings.
AppSettings(
"XmlActivationServiceUrl")
client.
Proxy =
New System.Net.
WebProxy(
"http://domain.com:80",
true)
If Not Me.
ActivateInstallationLicenseFile(
licenseId,
password,
client,
licenseContent)
ThenReturn False
End IfReturn Me.
SaveLicenseFile(
licenseContent)
End Function
Using the default system proxy and credentials
When a system is behind a proxy server, it is common for the computer to be
configured to use a specific proxy server so that things operate normally.
These settings are typically configured through Internet Explorer's
Tools/Internet Options menu, under the "Connection" tab. It is possible to
use the same configuration found here, and the excerpt of example code below
shows how this may be used by modifying the
ActivateOnline method in the samples. The
highlighted lines are the ones that
differ from the code for using a specified proxy server (from the section above).
- C#
- public bool ActivateOnline(Int32 licenseId, string password)
{
string licenseContent =
"";
com.softwarekey.Client.WebService.XmlActivationService.
XmlActivationService client =
new com.softwarekey.Client.WebService.XmlActivationService.
XmlActivationService();
client.
Url =
ConfigurationSettings.
AppSettings[
"XmlActivationServiceUrl"];
client.Proxy = System.Net.WebRequest.GetSystemWebProxy();client.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;if (!
this.
ActivateInstallationLicenseFile(
licenseId,
password,
client,
ref licenseContent))
return false;
return this.
SaveLicenseFile(
licenseContent);
}
- Visual Basic .NET
- Public Overloads Function ActivateOnline(ByVal licenseId As Int32, ByVal password As String) As Boolean
Dim licenseContent As String =
""Dim client As New com.softwarekey.Client.WebService.XmlActivationService.
XmlActivationService()
client.
Url =
ConfigurationSettings.
AppSettings(
"XmlActivationServiceUrl")
client.Proxy = System.Net.WebRequest.GetSystemWebProxy()client.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentialsIf Not Me.
ActivateInstallationLicenseFile(
licenseId,
password,
client,
licenseContent)
ThenReturn False
End IfReturn Me.
SaveLicenseFile(
licenseContent)
End Function