开发者

.net : How to correctly catch an internet connection error during web service call?

开发者 https://www.devze.com 2022-12-20 08:54 出处:网络
I am calling a 3rd party web service, during testing I am simulating what would happen if the web server lost internet connectivity by disabling the network adapter during a web service operation.

I am calling a 3rd party web service, during testing I am simulating what would happen if the web server lost internet connectivity by disabling the network adapter during a web service operation.

I have a simple try/ catch scenario.

The ex.message is : There is an error in XML document (1, 1709).

The ex.InnerException.Message : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

During a 2nd test : Unable to read data from the transport connection: An established connection was aborted by the software in your host machine

My question is rather than catching a general exception, how can I catch a more specific exception relating to the transport? I've already tried a System.Net.Sockets.SocketException, but this is the wrong object type for this operation.

Any ideas?

Just for clarification, I need an error type that only occurs during a network operation fail, because I'm had a case where the web service provider made changes to their WSDL also producing an error in xml... so I need to drill down and get specific with this one开发者_StackOverflow...

Tried

catch (System.Net.WebException ex)
catch (System.Web.Services.Protocols.SoapException soapEx)
catch (System.Net.Sockets.SocketException socketException)

None of the above work.

Thanks in advance


Catch SoapException and read the Detail property.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号