Wednesday 29 June 2011

Name xxx is not bound in this context - Part II

In the first part of this blog I covered the cause of this error message. But what if you want to use different web services in development and in production? It's not that difficult but Java does manage to hide it quite well. A little digging on Google and a lot of testing and re-testing and I did manage to get it to work.

One of the constructors used when creating a new web service declaration accepts two parameters; a URL and a QName. By passing the URL and Endpoint that we would like to use, we can redirect our web service call away from the original service URL located in the WSDL file and towards the new end point. So your code ends up looking like this:
private WSTixs service;
    
URL serviceEndPoint = new URL("http://mywebservice.com");
QName serviceQName = new QName("http://tempuri.org", "EndPoint");

webservices.EndPoint service = new webservices.EndPoint(serviceEndPoint, serviceQName);
Now in another of those traps for young players, and you will spend a lot of time on Google trying to solve this one. You MUST remove the @WebServiceRef if you have one. Otherwise your Servlet is going to come crashing down again with the 'Name xxx is not bound in this context' and no amount of debugging code is going to save you. Either comment the line out, or delete it altogether.

Hopefully someone is going to save some time with this because I spent a lot of it trying to solve it!

LCD

No comments:

Post a Comment