首页 > 解决方案 > javax.xml.ws.WebServiceException:未定义的端口类型,即使定义了端点接口

问题描述

即使我为服务端点接口 (SEI) 实现定义了 endpointInterface,我还是得到了 getport 错误

线程“主”javax.xml.ws.WebServiceException 中的异常:未定义的端口类型:{ http://soaptestclient.example.com/ }iSoapEndPoint

以下与同一问题相关的问题和答案并没有帮助我解决它

Java WebServiceException:带有 JBoss 的未定义端口类型

javax.xml.ws.WebServiceException:未定义的端口类型 Java Struts SOAP WSDL

服务端点接口

package com.example.soaptest1;
...
@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface iSoapEndPoint {
    @WebMethod String getHelloWorldAsString(String name);
}

服务端点接口实现

package com.example.soaptest1;
...
@WebService(endpointInterface = "com.example.soaptest1.iSoapEndPoint")
public class SoapEndPointImpl implements iSoapEndPoint{
    @Override
    public String getHelloWorldAsString(String name) {
        return "Hello World JAX-WS " + name;
    }    
}

服务端点发布者

public class SoapEndPointPublisher {
    public static void main(String[] args){
        Endpoint.publish("http://192.168.1.11:9999/ws/hello", new SoapEndPointImpl());
    }
}

最后是客户

    public class SoapClient {
        public static void main (String [] args) throws Exception{

            URL url = new URL("http://192.168.1.11:9999/ws/hello?wsdl");

            QName qname = new QName("http://soaptest1.example.com/", "SoapEndPointImplService");

            Service service = Service.create(url,qname);

     if one has enough experience in "reading" wsdl 
            iSoapEndPoint soapEndPointInterface = service.getPort(iSoapEndPoint.class);  
     //The interface iSoapEndPoint was copied from the EndPoint 
     //Java project to the client Java project so that I can import it since I'm not using wsimport      
            System.out.println(soapEndPointInterface.getHelloWorldAsString("Hello"));
        }
    }

标签: javasoap

解决方案


推荐阅读