错误信息:
严重: Servlet.service() for servlet jsp threw exception
javax.xml.ws.WebServiceException: WSDL Metadata not available to create the proxy, either Service instance or ServiceEndpointInterface com.java.web.services.StudentService should have WSDL information
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:343)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:355)
at javax.xml.ws.Service.getPort(Service.java:161)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:78)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:662)
解决方案:
原因是因为使用JAX-WS调用webservcie时 ,没有指定Url地址,导致此错误的发生;
public class WebServiceClient {
public static void main(String[] args) throws MalformedURLException {
URL url = new URL("http://127.0.0.1:8080/WebService?wsdl");
//第一个参数是webservice的URI;
//第二个参数是发布的WebService服务的名字;
QName qName = new QName("http://services.web.java.com/","StudentServiceImplService");
//创建服务;
//Service service = Service.create(qName); //此处需要指定url;正确的如下: Service service = Service.create(url,qName);
//提取服务端口;
StudentService studentService = service.getPort(StudentService.class);
String result = studentService.sayHello("Zhangsan");
System.out.println(result);
}
}