我从jboss'helloworld-ws'中选了一个例子。我创建了一个基于客户端spring的web应用程序helloworld-ws-test。然后我通过jboss webservice客户端创建了一个webservice客户端(它还使用main方法创建了一个示例客户端) 我在jboss 6.1-eap服务器中部署了这两个应用程序。因此,如果我尝试通过示例客户端访问webservice,我将获得输出没有任何问题但是当我将相同的代码复制到helloworld-ws-test Web应用程序控制器并尝试访问webservice时,我得到以下异常。
11:51:55,025 DEBUG [org.springframework.web.servlet.DispatcherServlet] (http-localhost/127.0.0.1:8080-1) Could not complete request: 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.jboss.wsf.stack.cxf.client.ProviderImpl$JBossWSServiceImpl.<init>(ProviderImpl.java:479)
at org.jboss.wsf.stack.cxf.client.ProviderImpl.createServiceDelegate(ProviderImpl.java:165)
at javax.xml.ws.Service.<init>(Service.java:57) [jboss-jaxws-api_2.2_spec-2.0.1.Final-redhat-2.jar:2.0.1.Final-redhat-2]
at org.jboss.jbossas.quickstarts.wshelloworld.helloworld.HelloWorldService_Service.<init>(HelloWorldService_Service.java:47) [classes:]
at org.jboss.as.quickstarts.mvc.MemberController.displaySortedMembers(MemberController.java:20) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_09]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_09]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_09]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_09]
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_09]
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:203)
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:147)
... 36 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF; was expecting a close tag for element <HTML>
at [row,col,system-id]: [4,0,"http://localhost:8080/helloworld-ws/HelloWorldService?wsdl"]
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:243)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:192)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:98)
... 38 more
Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF; was expecting a close tag for element <HTML>
at [row,col,system-id]: [4,0,"http://localhost:8080/helloworld-ws/HelloWorldService?wsdl"]
at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:677)
at com.ctc.wstx.sr.BasicStreamReader.throwUnexpectedEOF(BasicStreamReader.java:5532)
at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2720)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1072)
at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1250)
at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1144)
at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1071)
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:234)
... 40 more
11:51:55,037 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/helloworld-ws-test].[jboss-as-kitchensink]] (http-localhost/127.0.0.1:8080-1) JBWEB000236: Servlet.service() for servlet jboss-as-kitchensink threw exception: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF; was expecting a close tag for element <HTML>
at [row,col,system-id]: [4,0,"http://localhost:8080/helloworld-ws/HelloWorldService?wsdl"]
at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:677)
at com.ctc.wstx.sr.BasicStreamReader.throwUnexpectedEOF(BasicStreamReader.java:5532)
at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2720)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1072)
at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1250)
at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1144)
at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1071)
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:234)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:192)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:98)
at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:203)
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:147)
at org.jboss.wsf.stack.cxf.client.ProviderImpl$JBossWSServiceImpl.<init>(ProviderImpl.java:479)
at org.jboss.wsf.stack.cxf.client.ProviderImpl.createServiceDelegate(ProviderImpl.java:165)
at javax.xml.ws.Service.<init>(Service.java:57) [jboss-jaxws-api_2.2_spec-2.0.1.Final-redhat-2.jar:2.0.1.Final-redhat-2]
at org.jboss.jbossas.quickstarts.wshelloworld.helloworld.HelloWorldService_Service.<init>(HelloWorldService_Service.java:47) [classes:]
at org.jboss.as.quickstarts.mvc.MemberController.displaySortedMembers(MemberController.java:20) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_09]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_09]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_09]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_09]
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_09]
WSDL
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.jboss.org/jbossas/quickstarts/wshelloworld/HelloWorld" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="HelloWorldService" targetNamespace="http://www.jboss.org/jbossas/quickstarts/wshelloworld/HelloWorld">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.jboss.org/jbossas/quickstarts/wshelloworld/HelloWorld" elementFormDefault="unqualified" targetNamespace="http://www.jboss.org/jbossas/quickstarts/wshelloworld/HelloWorld" version="1.0">
<xs:element name="sayHello" type="tns:sayHello"/>
<xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/>
<xs:element name="sayHelloToName" type="tns:sayHelloToName"/>
<xs:element name="sayHelloToNameResponse" type="tns:sayHelloToNameResponse"/>
<xs:element name="sayHelloToNames" type="tns:sayHelloToNames"/>
<xs:element name="sayHelloToNamesResponse" type="tns:sayHelloToNamesResponse"/>
<xs:complexType name="sayHello">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="sayHelloResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayHelloToNames">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayHelloToNamesResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayHelloToName">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayHelloToNameResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="sayHelloToNameResponse">
<wsdl:part element="tns:sayHelloToNameResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="sayHelloToNamesResponse">
<wsdl:part element="tns:sayHelloToNamesResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="sayHelloToName">
<wsdl:part element="tns:sayHelloToName" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="sayHelloToNames">
<wsdl:part element="tns:sayHelloToNames" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="sayHelloResponse">
<wsdl:part element="tns:sayHelloResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="sayHello">
<wsdl:part element="tns:sayHello" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="HelloWorldService">
<wsdl:operation name="sayHello">
<wsdl:input message="tns:sayHello" name="sayHello"></wsdl:input>
<wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="sayHelloToNames">
<wsdl:input message="tns:sayHelloToNames" name="sayHelloToNames"></wsdl:input>
<wsdl:output message="tns:sayHelloToNamesResponse" name="sayHelloToNamesResponse"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="sayHelloToName">
<wsdl:input message="tns:sayHelloToName" name="sayHelloToName"></wsdl:input>
<wsdl:output message="tns:sayHelloToNameResponse" name="sayHelloToNameResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloWorldServiceSoapBinding" type="tns:HelloWorldService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sayHello">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="sayHello">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayHelloResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sayHelloToNames">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="sayHelloToNames">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayHelloToNamesResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sayHelloToName">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="sayHelloToName">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayHelloToNameResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWorldService">
<wsdl:port binding="tns:HelloWorldServiceSoapBinding" name="HelloWorld">
<soap:address location="http://localhost:8080/helloworld-ws/HelloWorldService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
HelloWorldService.java
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.quickstarts.wshelloworld;
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebService;
/**
* A simple example of how to setup a JAX-WS Web Service. It can say hello to everyone or to someone in particular.
*
* @author lnewson@redhat.com
*/
@WebService(targetNamespace = "http://www.jboss.org/jbossas/quickstarts/wshelloworld/HelloWorld")
public interface HelloWorldService {
/**
* Say hello as a response
*
* @return A simple hello world message
*/
@WebMethod
public String sayHello();
/**
* Say hello to someone precisely
*
* @param name The name of the person to say hello to
* @return the number of current bookings
*/
@WebMethod
public String sayHelloToName(String name);
/**
* Say hello to a list of people
*
* @param names The list of names to say hello to
* @return the number of current bookings
*/
@WebMethod
public String sayHelloToNames(List<String> names);
}
HelloWorldServiceImpl.java
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.quickstarts.wshelloworld;
import java.util.ArrayList;
import java.util.List;
import javax.jws.WebService;
/**
* The implementation of the HelloWorld JAX-WS Web Service.
*
* @author lnewson@redhat.com
*/
@WebService(serviceName = "HelloWorldService", portName = "HelloWorld", name = "HelloWorld", endpointInterface = "org.jboss.as.quickstarts.wshelloworld.HelloWorldService", targetNamespace = "http://www.jboss.org/jbossas/quickstarts/wshelloworld/HelloWorld")
public class HelloWorldServiceImpl implements HelloWorldService {
@Override
public String sayHello() {
return "Hello World!";
}
@Override
public String sayHelloToName(final String name) {
/* Create a list with just the one value */
final List<String> names = new ArrayList<String>();
names.add(name);
return sayHelloToNames(names);
}
@Override
public String sayHelloToNames(final List<String> names) {
return "Hello " + createNameListString(names);
}
/**
* Creates a list of names separated by commas or an and symbol if its the last separation. This is then used to say hello to
* the list of names.
*
* i.e. if the input was {John, Mary, Luke} the output would be John, Mary & Luke
*
* @param names A list of names
* @return The list of names separated as described above.
*/
private String createNameListString(final List<String> names) {
/*
* If the list is null or empty then assume the call was anonymous.
*/
if (names == null || names.isEmpty()) {
return "Anonymous!";
}
final StringBuilder nameBuilder = new StringBuilder();
for (int i = 0; i < names.size(); i++) {
/*
* Add the separator if its not the first string or the last separator since that should be an and (&) symbol.
*/
if (i != 0 && i != names.size() - 1)
nameBuilder.append(", ");
else if (i != 0 && i == names.size() - 1)
nameBuilder.append(" & ");
nameBuilder.append(names.get(i));
}
nameBuilder.append("!");
return nameBuilder.toString();
}
}
ClientSample.java
package org.jboss.jbossas.quickstarts.wshelloworld.helloworld.clientsample;
import org.jboss.jbossas.quickstarts.wshelloworld.helloworld.*;
public class ClientSample {
public static void main(String[] args) {
System.out.println("***********************");
System.out.println("Create Web Service Client...");
HelloWorldService_Service service1 = new HelloWorldService_Service();
System.out.println("Create Web Service...");
HelloWorldService port1 = service1.getHelloWorld();
System.out.println("Call Web Service Operation...");
System.out.println("Server said: " + port1.sayHello());
System.out.println("Server said: " + port1.sayHelloToNames(null));
//Please input the parameters instead of 'null' for the upper method!
System.out.println("Server said: " + port1.sayHelloToName(null));
//Please input the parameters instead of 'null' for the upper method!
System.out.println("Create Web Service...");
HelloWorldService port2 = service1.getHelloWorld();
System.out.println("Call Web Service Operation...");
System.out.println("Server said: " + port2.sayHello());
System.out.println("Server said: " + port2.sayHelloToNames(null));
//Please input the parameters instead of 'null' for the upper method!
System.out.println("Server said: " + port2.sayHelloToName(null));
//Please input the parameters instead of 'null' for the upper method!
System.out.println("***********************");
System.out.println("Call Over!");
}
}
MemberController.java
package org.jboss.as.quickstarts.mvc;
import org.jboss.jbossas.quickstarts.wshelloworld.helloworld.HelloWorldService;
import org.jboss.jbossas.quickstarts.wshelloworld.helloworld.HelloWorldService_Service;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping(value = "/")
public class MemberController {
@RequestMapping(method=RequestMethod.GET)
public String displaySortedMembers(Model model) {
System.out.println("***********************");
System.out.println("Create Web Service Client...");
HelloWorldService_Service service1 = new HelloWorldService_Service();
System.out.println("Create Web Service...");
HelloWorldService port1 = service1.getHelloWorld();
System.out.println("Call Web Service Operation...");
System.out.println("Server said: " + port1.sayHello());
System.out.println("Server said: " + port1.sayHelloToNames(null));
//Please input the parameters instead of 'null' for the upper method!
System.out.println("Server said: " + port1.sayHelloToName(null));
//Please input the parameters instead of 'null' for the upper method!
System.out.println("Create Web Service...");
HelloWorldService port2 = service1.getHelloWorld();
System.out.println("Call Web Service Operation...");
System.out.println("Server said: " + port2.sayHello());
System.out.println("Server said: " + port2.sayHelloToNames(null));
//Please input the parameters instead of 'null' for the upper method!
System.out.println("Server said: " + port2.sayHelloToName(null));
//Please input the parameters instead of 'null' for the upper method!
System.out.println("***********************");
System.out.println("Call Over!");
return "index";
}
}
答案 0 :(得分:0)
您是否已将所有必需的jar文件放入客户端。请先检查,然后检查您的cxf jar文件版本是否舒适。确保在客户端类中定义了正确的wsdl名称(例如“http:// something:7101 / TestWSA / WsaWebServiceTest?WSDL”)。注意,首先查看您的jar文件版本。我认为,它会起作用。谢谢!