[PATCH] Service.createDispatch(QName, *) doesn't know about the ports available

From: <>
Date: Thu, 1 Sep 2005 11:27:17 +0100

I've been trying to use the createDispatch(QName, ...) method for a
service I've created from a WSDL. Unfortunately the WebService
implementation does not use the WSDL information to know about the
available ports and their binding detals so it throws an exception if
I try to create a Dispatcher for a known port.

The work around is to explicitly call addPort() first before using it
- but given that the WebService has parsed the WSDL and knows what
all the ports are it seems silly to force the user to add all the
ports that WebService already knows about right?

I'm assuming this is just an oversight/bug and that I'm the first to
hit this - please forgive me if I've misunderstood. As an experiment
I thought I'd try patch WebService to actually find the available
ports from the WSDL and use those by default which seems much nicer
and less surprising from an end users perspective. It turns out it
was very simple to do - I just added this new method to the
WebService class....

      * Looks up the dispatch port. If the port has not been added,
then try look in the WSDL to find it.
     protected PortInfoBase getDispatchPort(QName port) {
         PortInfoBase answer = dispatchPorts.get(port);
         if (answer == null) {
             // lets try find it in the WSDL
             WSDLContext wsdlContext = serviceContext.getWsdlContext();
             QName serviceName = serviceContext.getServiceName();
             Binding binding = wsdlContext.getWsdlBinding
(serviceName, port);
             if (binding != null) {
                 try {
                     URI bindingId = new URI(binding.getBindingId());
                     String endpointAddress = wsdlContext.getEndpoint
                     addPort(port, bindingId, endpointAddress );
                     answer = dispatchPorts.get(port);
                 catch (URISyntaxException e) {
                     throw new WebServiceException(e);
         return answer;

then replaced the 2 uses of dispatchPorts.get(port) with a call to
this method. I've attached my amended file too if that makes it
easier to apply the patch.

This change works great for me - does this sound a reasonable patch
to apply?