Exception error while using .NET web service client code

While using my .NET application to access TRKD services, I keep getting the following exception:
“CommunicationException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.”
Can you please tell me what is causing this and how I can resolce it when it happens?
Best Answer
-
This exception is likely to be caused by a 100 (Continue) behavior issue which happens sometimes on .NET web-service clients because of the way .NET Framework sends requests to a web-service. This is a rather known problem with .NET web-service clients and occurs not only with TRKD but it doesn't happen with all application all the time so if you are the one facing it, the below information is for you.
The purpose of the 100 (Continue) status is to allow a client that is sending a request message with a request body to determine if the origin server is willing to accept the request (based on the request headers) before the client sends the request body. In some cases, it might either be inappropriate or highly inefficient for the client to send the body if the server will reject the message without looking at the body.
In case the request is acceptable, the client receives the HTTP 100 response and then transmits the body as it had promised. The traffic for this scenario looks somewhat like this:
Client->Server
POST /Page HTTP/1.1
Content-Type: text/plain
Content-Length: 26
Expect: Continue
Server->Client
HTTP/1.1 100 Continue
Client->Server
SOAP Request
Server->Client
HTTP/1.1 200 OK
Upon receiving a request which includes an Expect request-header field with the 100 (Continue) expectation, an origin server must either respond with 100 (Continue) status and continue to read from the input stream, or respond with a final status code. The origin server must not wait for the request body before sending the 100 (Continue) response. If it responds with a final status code, it may close the transport connection or it may continue to read and discard the rest of the request.
Closing the connection is not required in HTTP 1.1, although it may happen — say, if persistent connections are disabled altogether, the number of file descriptors reserved for persistent connections are currently exhausted, or the response doesn't contain a Content-Length header or isn't chunked.
In case a proxy gets 100 (Continue) request and knows that the version of the next-hop server is HTTP/1.0 or lower, it will not forward the request, and it will respond with a 417 (Expectation Failed) status.
In order to prevent connection close from server without getting a request, therefore to avoid the .NET exception "A connection that was expected to be kept alive was closed by the server", it is possible in .NET todisable the 100 (Continue) behavior in an application. The following line should be put somewhere in the code before the initial calls occur:System.Net.ServicePointManager.Expect100Continue = False;
Links on the subject:
• Issue investigation: http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/246ffc07-1cab-44b5-b529-f1135866ebca/
• How to make a more precise adjustment: http://geekswithblogs.net/mnf/archive/2009/01/13/specify-expect100continuefalse-in-web-service-client.aspx
• Specification: http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.expect100continue.aspx
• HTTP 1.1. RFC 2616. Connections chapter: http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 689 Datastream
- 1.4K DSS
- 626 Eikon COM
- 5.2K Eikon Data APIs
- 11 Electronic Trading
- 1 Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 255 ETA
- 558 WebSocket API
- 39 FX Venues
- 15 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 277 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 23 RDMS
- 2K Refinitiv Data Platform
- 705 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 106 UPA
- 194 TREP Infrastructure
- 229 TRKD
- 918 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 94 Workspace SDK
- 11 Element Framework
- 5 Grid
- 19 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛