Did you transfer the backup for your 3GS to your iPhone 4S, or did you set up your 4S as new?
What does not work for a while mean exacty? The 4S shows being connected to your wi-fi network but no internet access with any apps, or the connection is completely lost and you can't re-connect to the network?
If the former or regardless, on your iPhone go to Settings > General > Reset and select Reset Network Settings. This will delete all saved wi-fi networks and settings from your iPhone. Follow this by re-joining the network.