Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve ServiceConstructionException: Could not find definition for service?

I have a simple application with an web service created with Apache CXF. This application works when I run the server and the client (as Java applications). When I try to access the application /services URL which is mapped in web.xml, Tomcat gives me 404 error. When I run the project I receive:

org.apache.cxf.service.factory.ServiceConstructionException: Could not find definition for service {http://sendmessage/}SendMessage

If anyone has any hints related to this error I would be glad to hear them. (I searched google and couldn't find something relevant to my situation)

Thank you!

like image 269
ariel_ro Avatar asked Jan 13 '11 12:01

ariel_ro


3 Answers

I had same error, mine was related to namespace which were different in wsdl and webservice. So I changed them to the same.

WSDL:

<wsdl:definitions name=""
    targetNamespace="http://www.example.org/yourservice/"

Webservice class:

@WebService(targetNamespace = "http://www.example.org/yourservice/",
.........
like image 134
TastyCode Avatar answered Nov 12 '22 00:11

TastyCode


Even I had a similar issue. Fixed it by updating the jaxws:endpoint. I added the serviceName (mapping to the name present in the WSDL file) with the name space as defined in the "targetNamespace" defined in the wsdl:definitions tag.

<jaxws:endpoint id=".." implementor="..." serviceName="s:SERVICE_NAME_IN_WSDL"
xmlns:s="TARGET_NAME_SPACE_WSDL_DEFINTIONS"></jaxws:endpoint>

edited(06Jul)
Also, I have today that, with Apache CXF 3.0.5 version this issue is not coming; But with Apache CXF 3.1 version, this is coming.

like image 29
S R Chaitanya Avatar answered Nov 11 '22 23:11

S R Chaitanya


ServiceConstructionException can occur at various stages when cxf compares the provided service, port and binding name with the wsdl it has already parsed. In this case ( and in most cases) it looks to be namespace issue.

{http://sendmessage/}SendMessage is either not present in parsed wsdl or the service name does not match with the QName present in the WSDL. There are other cases as well where binding or port does not match, one might receive the same exception. Following is a code snippit from org.apache.cxf.wsdl11.WSDLServiceFactory.create() method where it all happens.

If things are not clear why exactly it is happening your best bet is to debug this piece of code and see where it is failing and what is there in parsed wdsl definition (com.ibm.wsdl.DefinitionImpl in wsdl4j.jar).

        javax.wsdl.Service wsdlService = definition.getService(serviceName);
        if (wsdlService == null) {
            if ((!PartialWSDLProcessor.isServiceExisted(definition, serviceName))
                && (!PartialWSDLProcessor.isBindingExisted(definition, serviceName))
                && (PartialWSDLProcessor.isPortTypeExisted(definition, serviceName))) {
                try {
                    Map<QName, PortType> portTypes = CastUtils.cast(definition.getPortTypes());
                    String existPortName = null;
                    PortType portType = null;
                    for (QName existPortQName : portTypes.keySet()) {
                        existPortName = existPortQName.getLocalPart();
                        if (serviceName.getLocalPart().contains(existPortName)) {
                            portType = portTypes.get(existPortQName);
                            break;
                        }
                    }
                    WSDLFactory factory = WSDLFactory.newInstance();
                    ExtensionRegistry extReg = factory.newPopulatedExtensionRegistry();
                    Binding binding = PartialWSDLProcessor.doAppendBinding(definition, 
                                                                           existPortName, portType, extReg);
                    definition.addBinding(binding);
                    wsdlService = PartialWSDLProcessor.doAppendService(definition, 
                                                                       existPortName, extReg, binding);
                    definition.addService(wsdlService);
                } catch (Exception e) {
                    throw new ServiceConstructionException(new Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
                }
            } else {
                throw new ServiceConstructionException(new Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
            }

PS: I know this issue was opened back in 2011 but recently I faced the same issue and was able to resolve it. I hope it help others who are facing this issue.

like image 1
Rajeev Singh Avatar answered Nov 11 '22 22:11

Rajeev Singh