You are assuming that you would have a path for authentication that is one level after the web context root(say http://localhost:8080/dsdataserver/dsl.svc) but the original path could be http://localhost:8080/dsdataserver/dsl.svc/OW5000/1/OpenWorks-SRL_HOU_OWNEW_SALT3D/.

In that case picking the last "/" won't work. You should look at the Reference method to give you the path till the web context and attach the relative path after the web context root.