0

I have an application which consumes a WCF service via a Service Reference. We're doing some failure testing and we'd like to be able to model the service itself failing, but in this case can't stop the service. What's more, this needs to happen while the application is running and return to functionality after connectivity is restored.

I've tried using firewall rules for this, but for some reason if it connects fine initially then it will continue to connect fine afterwards. I assume this is because it makes a single initial connection then keeps it alive afterwards.

I thought maybe that I could change the hosts file, but I have run into the same issue. It connects just fine, I change hosts (and confirm that it redirects things like ping), but the app continues to connect just fine.

I've tried a number of things, such as ipconfig/flushdns. Is there anything else I can do? I considered creating a script to temporarily disrupt the outbound connections and force a reconnect. The problem is that if I'm RDPing into the machine, this will likely break my own connection! Which is undesirable.

Is there a way to either make the service client respect changes to the Hosts file, make it respect changes to the firewall, or easily and temporarily disrupt outbound connections without disrupting RDP?

EDIT: As a note, the connection utilizes Keep Alive and this is something that we cannot change. Further, we are not using app.config, so we also cannot change that. Lastly, we cannot install any additional software on the machine it turns out. Everything must be internal to the OS to do this.

Nate Diamond
  • 5,525
  • 2
  • 31
  • 57
  • Do you have the ability to spin up a test instance of the service in a Hyper-V VM on the same host as the client? If so you may be able to "simulate" a connectivity failure at the virtual switch. – lesscode May 23 '16 at 22:26
  • I don't unfortunately, as virtualization is not available on the client machine. – Nate Diamond May 23 '16 at 22:30
  • [CurrPorts](http://www.nirsoft.net/utils/cports.html) from Nirsoft looks like it might help. It lists currently open connections and will let you kill individual connections if you run it with admin privileges. – WarrenG May 24 '16 at 04:58
  • @WarrenG That looks like it may just work. I'll be trying it out in the next few days. If it does work, I'll come back and you can add it as an answer for me to accept (or just add it as an answer and I can accept it if it works). – Nate Diamond May 24 '16 at 16:24
  • Why dont you just break the app.config file instead of the hosts file. You can do this at runtime, https://blogs.msdn.microsoft.com/youssefm/2010/01/21/how-to-change-net-configuration-files-at-runtime-including-for-wcf/ – Murray Foxcroft May 26 '16 at 09:04
  • We're not using the app.config for endpoint configuration at the moment unfortunately. Otherwise that might work, and may work for someone else. – Nate Diamond May 27 '16 at 18:59
  • `Everything must be internal to the OS` - but you did not specify which OS (win 7, 8.1 ...) – Vojtěch Dohnal May 27 '16 at 20:26
  • It's true, I didn't want to be specific for security reasons. I can say it's a recent version of Windows Server though. I'll add a tag to that end. – Nate Diamond May 27 '16 at 20:46
  • May I ask *why* you are doing failure testing in a production environment? Don't you have a development environment for these things? – Lucas Trzesniewski May 28 '16 at 10:45

2 Answers2

0

1) You can use Fiddler and intercept the connection on the client side. Note that you should run Fiddler under account you run your client. Probably it is the way you should go.

2) Or you can try to fix your current approach. As you the described behavior it may help to disable "keep-alive". See the instruction from here:

Open IIS Manager and navigate to the level you want to manage. In Features View, double-click HTTP Response Headers. On the HTTP Response Headers page, in the Actions pane, click Set Common Headers. In the Set Common HTTP Response Headers dialog box, select the Disable HTTP keep-alive check box and then click OK. Note: This will disable the HTTP keep-alive for all the processes under IIS, not just for a one virtual directory.

Regards,

M.R.ASHWINPRABHU

But it seems to be less convenient way to work with firewall rules than to just use Fiddler.

Sergey L
  • 1,402
  • 1
  • 9
  • 11
  • Option 1 is definitely a possibility. Others in the comments above suggested a few other tools with similar capabilities. Unfortunately for this instance we can't install any additional software on the target machine to do this, so we'd need an internal windows tool (or some batch/powershell script/command we could run). Further, Option 2 won't work because we a) don't own the service and b) want the Keep Alive feature for client efficiency. As such, manually turning off keep alive in the application is untenable. – Nate Diamond May 27 '16 at 19:02
0

Download & run TCPView from Sysinternals. It requires no installation. There you will see list of processes. Just right click on the process YourAppName.exe with Remote Address = YourServerNameOrIP and click on Close connection. You may find other inspiration in answers to this question.

You must do it meanwhile the WCF communication is active, you should then recieve this exception:

The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '{0}'.

After closing the connection with TCPView blocking with firewall rule should work for a new connection.

If you need a script, check this answer.

Community
  • 1
  • 1
Vojtěch Dohnal
  • 7,867
  • 3
  • 43
  • 105
  • Just to be sure, are you starting a connection with Keep Alive and maintaining the program open, then changing the firewall rule? The problem is after the connection is established that setting the firewall rule doesn't do anything. So the process is: Open connection, then set firewall. This will not work. If you did: Set Firewall, then Open Connection, then it will work as you said. – Nate Diamond May 27 '16 at 20:11