Web services 如何解决ServiceConstructionException:找不到服务的定义?

Web services 如何解决ServiceConstructionException:找不到服务的定义?,web-services,cxf,Web Services,Cxf,我有一个简单的应用程序,它使用apachecxf创建了一个web服务。当我运行服务器和客户机(作为Javaapplications)时,这个应用程序就会工作。当我尝试访问映射在web.xml中的应用程序/servicesURL时,Tomcat会给我404错误。当我运行项目时,我收到: org.apache.cxf.service.factory.ServiceConstructionException:找不到服务的定义{http://sendmessage/}发送消息 如果有人对这个错误有任何提

我有一个简单的应用程序,它使用
apachecxf
创建了一个web服务。当我运行服务器和客户机(作为
Java
applications)时,这个应用程序就会工作。当我尝试访问映射在
web.xml
中的应用程序
/services
URL时,
Tomcat
会给我
404
错误。当我运行项目时,我收到:

org.apache.cxf.service.factory.ServiceConstructionException:找不到服务的定义{http://sendmessage/}发送消息

如果有人对这个错误有任何提示,我会很高兴听到他们。(我搜索了谷歌,没有找到与我的情况相关的东西)


谢谢大家!

我也有同样的错误,我的错误与wsdl和webservice中不同的名称空间有关。所以我把它们改成了一样的

WSDL:


就连我也有类似的问题。 通过更新jaxws:endpoint修复了此问题。 我添加了serviceName(映射到WSDL文件中的名称),其名称空间在WSDL:definitions标记中定义的“targetNamespace”中定义

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

已编辑(7月6日)
此外,我今天还知道,对于Apache CXF 3.0.5版本,这个问题不会出现;
但是在Apache CXF 3.1版本中,这一点即将到来。

当CXF将提供的服务、端口和绑定名称与其已解析的wsdl进行比较时,ServiceConstructionException可能会在不同的阶段发生。在这种情况下(在大多数情况下),它看起来是名称空间问题

{http://sendmessage/}SendMessage
在已解析的wsdl中不存在,或者服务名称与wsdl中存在的名称不匹配。还有其他绑定或端口不匹配的情况,可能会收到相同的异常。下面是来自
org.apache.cxf.wsdl11.WSDLServiceFactory.create()
方法的代码片段,所有这些都发生在该方法中

如果还不清楚为什么会发生这种情况,那么最好的办法就是调试这段代码,看看它在哪里失败,以及解析的wdsl定义(wsdl4j.jar中的
com.ibm.wsdl.DefinitionImpl

javax.wsdl.Service wsdlService=definition.getService(serviceName);
if(wsdlService==null){
如果((!PartialWSDLProcessor.isServiceExisted(定义,serviceName))
&&(!PartialWSDLProcessor.isBindingExisted(定义、服务名称))
&&(PartialWSDLProcessor.isPortTypeExisted(定义、服务名称))){
试一试{
Map portTypes=CastUtils.cast(definition.getPortTypes());
字符串existPortName=null;
PortType PortType=null;
对于(QName existPortQName:portTypes.keySet()){
existPortName=existPortQName.getLocalPart();
if(serviceName.getLocalPart().contains(existPortName)){
portType=portTypes.get(existPortQName);
打破
}
}
WSDLFactory=WSDLFactory.newInstance();
ExtensionRegistry extReg=factory.newPopulatedExtensionRegistry();
Binding Binding=PartialWSDLProcessor.doAppendBinding(定义,
existPortName、portType、extReg);
定义。添加绑定(绑定);
wsdlService=PartialWSDLProcessor.doAppendService(定义,
existPortName、extReg、binding);
addService(wsdlService)的定义;
}捕获(例外e){
抛出新的ServiceConstructionException(新消息(“NO_-SUCH_-SERVICE_-EXC”,LOG,serviceName));
}
}否则{
抛出新的ServiceConstructionException(新消息(“NO_-SUCH_-SERVICE_-EXC”,LOG,serviceName));
}
PS:我知道这个问题早在2011年就开始了,但最近我遇到了同样的问题,并且能够解决它。我希望它能帮助其他面临这个问题的人

Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Could not find definition for port {http://localhost:9990/project/wsdl/targetName}targetNameSoap12.
at org.apache.cxf.wsdl11.WSDLServiceFactory.create(WSDLServiceFactory.java:179)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:428)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:548)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:265)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:215)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102)
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:159)
at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)
at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:456)
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:334)
... 13 more
已修复问题,请在web服务接口和契约WSDL中的注释@WebService(targetNameSpace=“targetNameSoap12”)处定义

例如:

...
<wsdl:service name='targetName'>
  <wsdl:port binding='tns:targetNameSoap12' name='targetNameSoap12'>
...
。。。
...
这里有一个相关的问题。
        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));
            }
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Could not find definition for port {http://localhost:9990/project/wsdl/targetName}targetNameSoap12.
at org.apache.cxf.wsdl11.WSDLServiceFactory.create(WSDLServiceFactory.java:179)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:428)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:548)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:265)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:215)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102)
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:159)
at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)
at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:456)
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:334)
... 13 more
...
<wsdl:service name='targetName'>
  <wsdl:port binding='tns:targetNameSoap12' name='targetNameSoap12'>
...