Export (0) Print
Expand All

ServicePoint.GetHashCode Method

.NET Framework 1.1

Gets the hash code for the ServicePoint.

[Visual Basic]
Overrides Public Function GetHashCode() As Integer
[C#]
public override int GetHashCode();
[C++]
public: int GetHashCode();
[JScript]
public override function GetHashCode() : int;

Return Value

The hash code for the ServicePoint.

Remarks

The hash code for ServicePoint A and B is the same if A.Equals(B) is true.

This method implements the Object.GetHashCode method.

Example

[Visual Basic, C#, C++] The following example uses the GetHashCode method to determine if two HttpWebRequest instances are pointing to the same ServicePoint.

[Visual Basic] 

' Create the first 'HttpWebRequest' object.
Dim myWebRequest1 As HttpWebRequest = CType(WebRequest.Create("http://www.microsoft.com"), HttpWebRequest)
' The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
Dim myWebResponse1 As HttpWebResponse = CType(myWebRequest1.GetResponse(), HttpWebResponse)
Dim myServicePoint1 As ServicePoint = myWebRequest1.ServicePoint

' Create the second 'HttpWebRequest' object with the same hostfragment as above.
Dim myWebRequest2 As HttpWebRequest = CType(WebRequest.Create("http://www.microsoft.com/windows"), HttpWebRequest)
Dim myWebResponse2 As HttpWebResponse = CType(myWebRequest2.GetResponse(), HttpWebResponse)
Dim myServicePoint2 As ServicePoint = myWebRequest2.ServicePoint
            
Console.WriteLine("The 'HashCode' for the first connection is:" + myServicePoint1.GetHashCode().ToString())

Console.WriteLine("The 'HashCode' for the second connection is:" + myServicePoint2.GetHashCode().ToString())
' Check whether the first and second 'HttpWebRequest' objects  connecting to the same internet 
' server are using the same 'ServicePoint'  or not
If myServicePoint1.GetHashCode().Equals(myServicePoint2.GetHashCode()) Then
    Console.WriteLine(ControlChars.Cr + "Two connections are created to the same Internet Server")
    Console.WriteLine("So same 'ServicePoint' is used for both the Connections")
End If


[C#] 
// Create the first 'HttpWebRequest' object.
HttpWebRequest myWebRequest1 = (HttpWebRequest) WebRequest.Create("http://www.microsoft.com");
// The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
HttpWebResponse myWebResponse1 =(HttpWebResponse)myWebRequest1.GetResponse();
ServicePoint myServicePoint1 = myWebRequest1.ServicePoint;
               

// Create the second 'HttpWebRequest' object with the same hostfragment as above.
HttpWebRequest myWebRequest2 =(HttpWebRequest) WebRequest.Create("http://www.microsoft.com/windows");
HttpWebResponse myWebResponse2 =(HttpWebResponse)myWebRequest2.GetResponse();
ServicePoint myServicePoint2 = myWebRequest2.ServicePoint;
                                 

Console.WriteLine("\nThe 'HashCode' for the first connection is:"+myServicePoint1.GetHashCode());

Console.WriteLine("The 'HashCode' for the second connection is:"+myServicePoint2.GetHashCode());
         
// Check whether the first and second 'HttpWebRequest' objects  connecting to the same internet 
// server are using the same 'ServicePoint' or not
               if(myServicePoint1.GetHashCode().Equals(myServicePoint2.GetHashCode()))
               {
                  Console.WriteLine("\nTwo connections are created to the same Internet Server");
                  Console.WriteLine("So same 'ServicePoint' is used for both the Connections");
               }

// Release all the response object resources.
myWebResponse1.Close();
myWebResponse2.Close();

[C++] 
// Create the first 'HttpWebRequest' object.
HttpWebRequest* myWebRequest1 =
   dynamic_cast<HttpWebRequest*> (WebRequest::Create(S"http://www.microsoft.com"));
// The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
HttpWebResponse* myWebResponse1 =
   dynamic_cast<HttpWebResponse*>(myWebRequest1->GetResponse());
ServicePoint* myServicePoint1 = myWebRequest1->ServicePoint;

// Create the second 'HttpWebRequest' object with the same hostfragment as above.
HttpWebRequest* myWebRequest2 =
   dynamic_cast<HttpWebRequest*> (WebRequest::Create(S"http://www.microsoft.com/windows"));
HttpWebResponse* myWebResponse2 =
   dynamic_cast<HttpWebResponse*>(myWebRequest2->GetResponse());
ServicePoint* myServicePoint2 = myWebRequest2->ServicePoint;

Console::WriteLine(S"\nThe 'HashCode' for the first connection is: {0}",
   __box(myServicePoint1->GetHashCode()));

Console::WriteLine(S"The 'HashCode' for the second connection is: {0}",
   __box(myServicePoint2->GetHashCode()));

// Check whether the first and second 'HttpWebRequest' objects  connecting to the same internet
// server are using the same 'ServicePoint' or not
if ( __box(myServicePoint1->GetHashCode()) -> Equals(__box(myServicePoint2->GetHashCode()) ) ) {
   Console::WriteLine(S"\nTwo connections are created to the same Internet Server");
   Console::WriteLine(S"So same 'ServicePoint' is used for both the Connections");
}

// Release all the response object resources.
myWebResponse1->Close();
myWebResponse2->Close();

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

ServicePoint Class | ServicePoint Members | System.Net Namespace

Show:
© 2014 Microsoft