This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!
Best Practices for Net Classes
The following recommedations will help you use the classes contained in System.Net to their best advantage:
- Use WebRequest and WebResponse whenever possible instead of typecasting to descendent classes. Applications that use WebRequest and WebResponse can take advantage of new Internet protocols without needing extensive code changes.
- When writing ASP+ applications that run on a server using the System.Net classes, it is often better from a performance standpoint to use the asynchronous methods for GetResponse and GetResponseStream.
- The number of connections opened to an Internet resource can have a significant impact on network performance and throughput. System.Net uses two connections per application per host by default. This number can be increased by setting the ConnectionLimit property in the ServicePoint instance for your connection.
- When writing socket level protocols, try to use TCPClient or UDPClient whenever possible instaed of writing directly to Sockets. These two client classes encapsulate the creation of TCP and UDP sockets without requiring you to handle the details of the connection.
- When accessing sites that require credentials, use the CredentialCache class to create a cache of credentials rather than supplying them with every request. The CredentialCache class will search the cache to find the appropriate credential to present with a request, relieving you of the responsibility of creating and presenting credentials based on the Uniform Resource Locator.