• 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;
        }
    } 
  • 相关阅读:
    sun.misc.BASE64Encoder找不到的解决方法
    eclipse里大小写转化的快捷键是什么
    jface viewer 理解
    如何在遗留代码基础上开发
    谈谈技术文档的编写
    jre build path 中的限制问题导致一些代码无法编译..如果设置
    android update automatically ( android 自动升级)
    各大集群存储产品点评
    关于@Autowired 注释为何不需要get Set
    VRML之desk
  • 原文地址:https://www.cnblogs.com/frankcui/p/10503876.html
Copyright © 2020-2023  润新知