locked
System.Net vs. WinHTTP RRS feed

  • Question

  • User-1907931736 posted

    Hi, all.

    I really need any advice anyone can give me; I'm at my wits end.  I have an application that consumes a large number of web services in each transaction -- mainly because we're using a web services enabler to integrate with a legacy mainframe system.  This has worked really well using WinHTTP, but I'm now trying to get onto managed .Net code using System.Net and the performance has degraded severely.  It still works, but it's not nearly as fast, which is a problem when you make as many web services calls as we are making.  Anybody have any suggestions on what I might be doing wrong:

    Here's the System.Net code that I'm using to consume the services...

            Dim oURI As New System.Uri(msURL)
            Dim oRequest As HttpWebRequest
            oRequest = CType(WebRequest.CreateDefault(oURI), HttpWebRequest)
            oRequest.Method = "POST"
            oRequest.ContentType = "text/html"
            oRequest.KeepAlive = True
            oRequest.Timeout() = miConnectorTimeout
            oRequest.Credentials = New NetworkCredential(msUserID, msPassword)
            Dim oResponse As HttpWebResponse

            oRequest.ContentLength = sHeader.Length
            Dim oStream As New StreamWriter(oRequest.GetRequestStream, Encoding.ASCII)
            oStream.Write(sHeader)
            oStream.Close()
            oResponse = CType(oRequest.GetResponse, HttpWebResponse)
            If oResponse.StatusCode = 200 Then
                Dim oReader As New StreamReader(oResponse.GetResponseStream)
                Return oReader.ReadToEnd
            ElseIf oResponse.StatusCode = 401 Then
                Return "Unauthorized"
            End If

    And here's the equivalent WinHTTP code that performs nearly twice as fast:

            Dim oXMLServer As New WinHttpRequest
            Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
            Const HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1

            oXMLServer.Open("POST", msURL, False)
            oXMLServer.SetCredentials(msUserID, msPassword, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER)

            oXMLServer.Send(sHeader)
            If oXMLServer.Status = 200 Then
                Return oXMLServer.ResponseText
            ElseIf oXMLServer.Status = 401 Then
                Return "Unauthorized"
            End If

    If anyone has any thoughts at all on how I might be able to switch to managed code without sacrificing the performance, please help!!!

    Thanks,
    Brian

    Friday, August 19, 2005 6:13 PM

All replies

  • User-915762844 posted

    Check your "maxconnection" setting in machine.config.  This setting determines how many simultaneous connections a web application can open to a particular host.  This defaults to 2 and can quickly become a bottleneck, especially when making large numbers of web service calls.  Raise it to something much higher (I believe the ideal is 12 per processor).


     

    Friday, August 19, 2005 11:42 PM