Thursday, November 11, 2010

Retrieve remote web service client host and IP

If you've created a web service, and you want to find out what the host or IP-address of the remote client is? The following code will be useful.

public class WebService {
WebServiceContext wsc;

public String webMethod() {
MessageContext mc = wsc.getMessageContext();
HttpServletRequest req = (HttpServletRequest)
return "Client: " +
req.getRemoteHost() + " (" +
req.getRemoteAddr() + ").";

The code above will return the host and IP-address of the remote web service client back to the client.

1 comment:

  1. Client Code Please ,
    i got null pointer exception (wsc.),