.NET Framework Bookmark and Share   
 index > Windows Communication Foundation > Manually closing Client connection / Client IP address
 

Manually closing Client connection / Client IP address

I am developing a WCF service that will need to manually manage client connections, as each client session will be associated with connections to other resources. I have a few issues I am struggling with, and would appreciate any help:

1) I have noticed that if more than 10 clients connect at once to my service and none of them call close(), the 11th client is denied. I am aware that I can increase the number of concurrent client connections, but this does not solve the denial of service vulnerability. As I am managing client connections myself, I need to have a way to manually close the client session/connection from within the host. Is there a call to do this?

2) I need to determine the client's IP address... any suggestions? I am using wsHttpBinding, so I'm assuming its available somewhere.

3) I also need to know how the System.ServiceModel.OperationContext.Current.SessionID is generated (see my other post [http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1813548&SiteID=1&mode=1])

Thanks in advance to anyone who can shed some light on these issues for me.


derek.thompson

For #1, I think you can use, for example, OperationContext.Current.Channel.Close() - does that address your scenario?

For #2, see http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1362556&SiteID=1, the short answer is, there's no way to get it without enlisting help from the client.

I assume #3 will get answered on the other thread.

Brian McNamara - MSFT

IsInitiating/IsTerminating are indeed good when the contract API has obvious 'start' and 'finish' methods.

Regarding timing out connections, see http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=876841&SiteID=1but I think you can just the ReceiveTimeout on the server binding to time out idle sessions rather than 'doing the work on your own'. However if that doesn't work for you for some reason, we can talk about other options.

Brian McNamara - MSFT

For #1, I think you can use, for example, OperationContext.Current.Channel.Close() - does that address your scenario?

For #2, see http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1362556&SiteID=1, the short answer is, there's no way to get it without enlisting help from the client.

I assume #3 will get answered on the other thread.

Brian McNamara - MSFT
Brian,

Thanks for your reply.

For #1 - Thanks for this suggestion - while reading up on this I found the IsInitiating and IsTerminating attributes that you can use with service contracts... which allowed me to terminate the session after a certain method was called. The issue now is that I have a thread that is hosting a timer that looks to see if any of the connections have timed out. If they have, I need to disconnect them and release any resources associated with them, including their connection to my service. In this case, I will need to close a client connection that may not be operating in the current context. Is there any way to close a client connection explicitly when you know it's session ID? Or, if you have any suggestions, I'm all ears... as I'm somewhat new to WCF programming.

For #2 - Thanks for that link. I'm still messing around with getting that to work, but apparently its at least possible.

For #3 - I'm hoping....

derek.thompson

IsInitiating/IsTerminating are indeed good when the contract API has obvious 'start' and 'finish' methods.

Regarding timing out connections, see http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=876841&SiteID=1but I think you can just the ReceiveTimeout on the server binding to time out idle sessions rather than 'doing the work on your own'. However if that doesn't work for you for some reason, we can talk about other options.

Brian McNamara - MSFT

You can use google to search for other answers

Custom Search

More Threads

• host wcf service for sliverlight client
• ServiceContractGenerator.NamespaceMappings bug ?
• tracing the client requests in WCF Host
• Best approach for propagating exceptions in a distributed enterprise architecture
• The caller was not authenticated by the service.
• How To Tell The Service The Host Is Closing?
• How to create a web service, assign it to a thread and to a named pipe
• DataSynchronization in WCF using PeerChannels
• Question about SAML tokens and bindings
• Open pdf in browser