• WebService [Debug] javax.xml.ws.WebServiceException: Undefined port type


    背景:

    使用JDK来开发java web service (Create a SOAP-based RPC style web service endpoint by using JAX-WS)。

    具体请看 -> WebService - 使用JDK开发WebService

    代码:

    import javax.xml.namespace.QName;
    import javax.xml.ws.Service;
    import java.net.MalformedURLException;
    import java.net.URL;
    
    public class WebServiceClient {
        public static void main(String[] args) throws MalformedURLException {
    
            URL url = new URL("http://127.0.0.1:8080/WS_Server/Webservice?wsdl");
            QName qname = new QName("http://webservice/", "WebServiceImplService");
    
            Service service = Service.create(url, qname);
    
            WebServiceI serviceI = service.getPort(WebServiceI.class);
    
            System.out.println(serviceI.sayHello("cuixunxu "));
    
        }

    错误:

    Exception in thread "main" javax.xml.ws.WebServiceException: Undefined port type: {http://webservice/}WebServiceI
        at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:456)
        at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:463)
        at javax.xml.ws.Service.getPort(Service.java:188)
        at webservice.client.WebServiceClient.main(WebServiceClient.java:19)

     解决方法:

    @WebService的接口类WebServiceI代码:

    package webservice;
    
    import javax.jws.WebMethod;
    import javax.jws.WebService;
    
    @WebService
    public interface WebServiceI {
    
        @WebMethod
        String sayHello(String name);
    
        @WebMethod
        String save(String name,String pwd);
    
    }

    WebServiceI接口的实现类WebServiceImpl类的代码:...注意,需要在@WebService注解后面加上接口的全路径

    package webservice;
    
    import webservice.WebServiceI;
    
    import javax.jws.WebService;
    
    @WebService(endpointInterface="webservice.WebServiceI")
    public class WebServiceImpl implements WebServiceI {
        @Override
        public String sayHello(String name) {
            return name + "is calling!!!";
        }
    
        @Override
        public String save(String name, String pwd) {
            return "Receive name: " + name + " and pwd: " + pwd;
        }
    } 
  • 相关阅读:
    Linux主要shell命令详解(下)
    mget命令, ftp命令详解
    VI 基本可视模式
    vim使用技巧
    cd及目录快速切换
    du命令解决linux磁盘空间满的问题(很不错的哦)
    Mysql删除数据后磁盘空间未释放的解决办法【转】
    MYSQL-innodb性能优化几个点
    Apache服务器出现Forbidden 403错误提示的解决方法总结
    MySQL 分区表原理及数据备份转移实战
  • 原文地址:https://www.cnblogs.com/frankcui/p/10503876.html
Copyright © 2020-2023  润新知