PLUSManaged: Adding Support for Proxy Servers

Important

If you are using or planning to use PLUSManagedGui in your application, this content may not be relevant to you since PLUSManagedGui automatically handles common functionality.

Some environments limit and monitor Internet connectivity using proxy servers (often places such as hospitals, government and military offices, etc...), which can have an impact on your application's ability to activate. This topic helps you to establish compatibility with most proxy servers.

Using the Sample Code

The easiest way to add support to your application is to copy some code from the sample projects included with Protection PLUS 5 SDK. This includes the ProxyServerCredentialsForm and the WebServiceHelper classes, which help you manage proxy server and proxy authentication credentials in your application. You will want to search the source code for any comments that start with TODO to see if there is any code that you should alter before shipping it with your application. At the top of your license implementation class, you can add a static/shared member as follows:

C#
private static WebServiceHelper m_WebServiceHelper = new WebServiceHelper();
VB.NET
Private Shared m_WebServiceHelper As New WebServiceHelper()

Then, you can update code which created web service objects directly to use the WebServiceHelper methods instead. Using XmlActivationService as an example:

C#
XmlActivationService ws = m_WebServiceHelper.GetNewXmlActivationServiceObject();
VB.NET
Dim ws As XmlActivationService = m_WebServiceHelper.GetNewXmlActivationServiceObject()

It is possible for the object to fail to initialize properly, so it is important to make sure the object returned is not null (C#) or Nothing (VB.NET). If you find you did not get an object back, check the WebServiceHelper object's LastError property for details.

Adding Customized Proxy Server Support

Using PLUSManaged to Detect Proxy Server Requirements

PLUSManaged includes a InternetConnectionInformation class (used by WebServiceHelper), which is designed to help you detect whether or not a proxy server and proxy authentication are required for your application to reach a URL.  Note that this class will perform a test HTTP request using the URL (or www.softwarekey.com by default) as soon as it is created, which may result in some delay.

Using Specified Proxy Server Credentials

Alternatively, the .NET Framework also contains supporting classes, which you may use with web service objects (such as XmlActivationService) directly.  Doing this might mean you may need to ask your users to configure proxy server information for your application when applicable, but could help avoid possible delays sometimes experienced during automatic testing. If your application already knows what host name (or IP address) and port to use for the proxy server, then you can set this using code similar to the following.

C#
XmlActivationService ws = new XmlActivationService();
ws.Proxy = new WebProxy("http://domain.com:80", true);
ws.Proxy.Credentials = new NetworkCredential("[username]", "[password]");
VB.NET
Dim ws As New XmlActivationService()
ws.Proxy = New WebProxy("http://domain.com:80", true)
ws.Proxy.Credentials = New NetworkCredential("[username]", "[password]")

In the example above, "http://domain.com:80" should be replaced with the server's host name, followed by the colon, and then the port number. Additionally, [username] and [password] should be replaced with the data entered by your users. Additionally, WebProxy and NetworkCredential both reside in the System.Net namespace, which you may need to add to your using (C#) or Imports (VB.NET) statements at the top of your source code.