Hello folks,
I am quite new to web service and developing a web service using netbeans6.0 IDE, where i have to know which client called/used the service, After googling i got code snippet like below
inject a WebServiceContext instance into your WebService class, and use it in each WebMethod to get the current request's MessageContext Map. Get the SERVLET_REQUEST item from that, cast as an HttpServletRequest. From that HttpServletRequest, you can invoke getRemoteAddr() to get the client's IP.
@WebService
public class MyService{
@Resource
WebServiceContext wsCtxt;
@WebMethod
public void myWebMethod(){
MessageContext msgCtxt = wsCtxt.getMessageContext();
HttpServletRequest req = (HttpServletRequest)msgCtxt.get(MessageContext.SERVLET_REQUEST);
String clientIP = req.getRemoteAddr();
}
But it throws error in my PC like
Service invocation threw an exception with message : null; Refer to the server log for more details
--------------------------------------------------------------------------------
Exceptions details : java.lang.reflect.InvocationTargetException
Is there any way that says client pc ip address using netbeans6.0 Or what went wrong in my code?
Largely Thanks in advance.
SRI.