我有一个 Tomcat 7.0 网络服务器,我用它来运行网络服务。 Web服务框架是CXF 2.5.2。
当从 Eclipse Web Service Explorer 测试 Web 服务时,一切正常。但是,当从 WSDL(使用 Eclipse)生成 Java 客户端并运行它时,从服务实现调用 super(wsdlLocation, serviceName)
时出现以下错误:
Exception in thread "main" javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:150)
at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:91)
at javax.xml.ws.Service.<init>(Service.java:77)
at test.Test_Service.<init>(Test_Service.java:43)
at test.Test_TestSOAP_Client.main(Test_TestSOAP_Client.java:47)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:94)
at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:204)
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:148)
... 4 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'c' (code 99) in start tag Expected a quote at [row,col,system-id]: [1,208,"http://www.example.com:8081/TestWS/services?wsdl"]
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:240)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:191)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:92)
... 6 more
Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'c' (code 99) in start tag Expected a quote at [row,col,system-id]: [1,208,"http://www.example.com:8081/TestWS/services?wsdl"]
at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:639)
at com.ctc.wstx.sr.BasicStreamReader.handleNsAttrs(BasicStreamReader.java:3005)
at com.ctc.wstx.sr.BasicStreamReader.handleStartElem(BasicStreamReader.java:2926)
at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2802)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1050)
at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1080)
at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:974)
at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:901)
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:231)
... 8 more
有趣的部分应该是 开始标记中的意外字符“c”(代码 99) Expected a quote
在 [row,col,system-id]: [1,208,"http://www.example.com:8081/TestWS/services?wsdl"]
消息。在检查生成的 services.wsdl 时,我发现问题出在元部分:
<meta http-equiv=content-type content="text/html; charset=UTF-8">
content-type
通常应该用引号引起来。这是使用的框架/服务器之一中的已知错误吗?我该怎么做才能解决这个问题?为什么使用Eclipse Web Services Explorer 就没有问题?它是否更容错(因为我的 Firefox 似乎也没有任何问题来显示生成的 wsdl 的图形表示)。
最佳答案
服务列表页面是一个 HTML 页面,列出了服务并提供指向这些服务的适当 WSDL 文档(或基于休息的服务的 WADL 文档)的链接。它不是 WSDL 文档。将其解析为 WSDL 是行不通的。
关于java - Web 服务器生成格式错误的 services.wsdl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9772857/