Click here to Skip to main content
15,172,951 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I am receiving the following response / error while calling and SAP Web Service from VB.Net 3.5 (Visual Studio 2008). We are sporadically receiving the error "The request was aborted: The request was canceled." According to research I have done, it is indicated that the web request is attempted to be reused by VB and closed by SAP. (or the request is closed mid-request). The advice that I have found is to override the WebRequest (httpWebrequest) object and set the KeepAlive property to false.

How do I access the object through a standard web service call? I do not see a way to do so. My code is below for reference.

Thanks in advance for your assistance.


Public Function ProcessRecords2() As Integer

     Dim service As New SAPws.ZPP_CREATE_TIME_TICKET
     Dim svcReq As New SAPws.ZppCreateTimeTicket
     Dim svcResp As SAPws.ZppCreateTimeTicketResponse
     -- clip - more declarations

     '   Set credentials to those included in the configuration file
     service.Credentials = New System.Net.NetworkCredential(My.Settings.UserName, My.Settings.Pswd, My.Settings.Domain)
     '   get the default proxy for the system to allow for firewall/proxy functionality
     service.Proxy = System.Net.WebRequest.GetSystemWebProxy()
     '   Set Time Out to allow for network traffic / SAP response
     service.Timeout = 25000

     ' set request envelope properties

     ' ========== CLIP ===========

     ' submit record to SAP and get response
     svcResp = service.ZppCreateTimeTicket(svcReq)

     ' Evaluate response and log
     ' ========== CLIP ===========
Updated 20-Aug-11 7:03am

1 solution

I am going to post a solution to my problem to assist those who may have issues in the future. This is based on Manuel9999 solution at[^] but translated to VB.

It turns out that the Web service class does have a protected function "GetWebRequest" inherited from SoapHttpClientprotocol.

In order to implement the solution, find the exact Web Service Name and Namespace (the namespace is usually what name you told Visual Studio to use to refer to the web service when adding the web service reference.)

To do so: open reference.vb file. The will be located under Web references\[Web service name]\Reference.Map. (You may have to click "Show All Files" at the top of the solution explorer.

Find the two names and replace the bracketed expressions with those values:

Option Strict Off
Option Explicit On
Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization
Imports System.Net

Namespace [NameSpace]

    Partial Public Class [Class Name]
        Inherits System.Web.Services.Protocols.SoapHttpClientProtocol

        Protected Overrides Function GetWebRequest(ByVal uri As Uri) _
            As WebRequest
            Dim webRequest As HttpWebRequest = CType( _
                MyBase.GetWebRequest(uri),  _

            webRequest.KeepAlive = False

            Return webRequest

        End Function

    End Class

End Namespace

Hope that help someone in the future avoid pulling their hair out.
Agustin Altamirano 27-Mar-20 8:25am
Thank you, I found this problem with an old .net project, your solution helped me to get rid on this problem... good stuff.
Andrew Woroniecki 11-May-20 13:40pm
Thank you, Raymond Hastie. My organization just encountered this issue after years of our web service connections to one of our partners working just fine. And it was just at one or two of our facilities. I was tearing my hair out and this solution worked perfectly and has improved reliability overall as well. Even in the year 2020 this is still helpful.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900