Java Web服务错误:com.ctc.wstx.exc.WstxEOFException:prolog中出现意外的EOF

Kum*_*ite 11 java wsdl web-services jax-ws wsimport

我在创建Java客户端并将其连接到正在运行的Web Service时遇到问题.

我使用以下代码:

Service myService  = null;
URL wsdlLocation = new URL("http://myservice?wsdl");
QName serviceName = new QName(wsdlLocation, "MyService");
Service myService = new Service(wsdlLocation, serviceName);
Run Code Online (Sandbox Code Playgroud)

使用以下命令创建Service类的位置:

wsimport -d gen -keep http://myservice?wsdl
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用Apache cxf 2.4的wsdl2java生成的客户端,但得到了相同的结果.

(我已经在我使用原始代码的代码中更改了此帖子的WSDL位置和服务类名称.)

但是当我使用新的Service()命令创建服务时,我在appserver上调用Web Service时遇到异常.但是:我用SOAP UI测试了wsdl位置,它运行得很好.此外,我使用Soap UI创建了一个模拟服务,我的Java客户端可以连接到它,调用它并获得结果.当我想要调用在appserver上运行的Web服务时,会出现问题.

堆栈跟踪:

javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
        at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:149)
        at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:98)
        at javax.xml.ws.Service.<init>(Service.java:76)
        at MyService.<init>(MyService.java:42)
        at mypackage.createService(AClass.java:288)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
        at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:100)
        at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:199)
        at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:147)
        ... 12 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
 at [row,col,system-id]: [1,0,"http://myservice?wsdl"]
        at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:256)
        at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:205)
        at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:98)
        ... 14 more
Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
 at [row,col,system-id]: [1,0,"http://myservice?wsdl"]
        at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:677)
        at com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2139)
        at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2045)
        at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1134)
        at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1248)
        at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1142)
        at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1069)
        at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:247)
        ... 16 more
Run Code Online (Sandbox Code Playgroud)

有人可以帮帮我吗?

Mic*_*l R 6

我遇到此错误,发现它似乎是由于使用了返回HTTP 302重定向而不是直接返回WSDL的URL所致。

我使用的URL格式为/Service?wsdl,该重定向到该格式的URL /Service/wsdl/Service.wsdl。一旦我直接使用重定向目标URL,一切都将正常工作。