javax.xml.ws.WebServiceException“X 不是有效端口。有效端口是:Y

javax.xml.ws.WebServiceException "X is not a valid port. Valid ports are: Y

我正在尝试使用我的 WSDL SOAP 服务:

public void batchReg(String[][] records){
    URL url = null;
    try {
        url = new URL("http://localhost:8080/EndUserService/?wsdl");
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (url == null) {
        System.out.println("Failed");
    }
    QName qname = new QName("http://EndUserService/","EndUserServiceImplService");
    Service service = Service.create(url,qname);
    EndUserService obj = service.getPort(qname,EndUserService.class);
    obj.register(records);
    System.out.println("Complete!");
}

然而当我运行这个时,我收到这个错误:

Exception in thread "main" javax.xml.ws.WebServiceException: {http://EndUserService/}EndUserServiceImplService is not a valid port. Valid ports are: {http://EndUserService/}EndUserServiceImplPort

然后我将 QName 声明更改为:

QName qname = new QName("http://EndUserService/","EndUserServiceImplPort");

但是我得到这个错误:

Exception in thread "main" javax.xml.ws.WebServiceException: {http://EndUserService/}EndUserServiceImplPort is not a valid service. Valid services are: {http://EndUserService/}EndUserServiceImplService

这是我以前的。

WSDL 摘录

<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://EndUserService/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://EndUserService/" name="EndUserServiceImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://jaxb.dev.java.net/array" schemaLocation="http://localhost:8080/EndUserService/?xsd=1"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://EndUserService/" schemaLocation="http://localhost:8080/EndUserService/?xsd=2"/>
</xsd:schema>
</types>

必须添加特定端口 QName

public void batchReg(String[][] records){
    URL url = null;
    try {
        url = new URL("http://localhost:8080/EndUserService/?wsdl");
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (url == null) {
        System.out.println("Failed");
    }
    QName qname = new QName("http://EndUserService/","EndUserServiceImplService");
    System.out.println(url);
    Service service = Service.create(url,qname);
    
    QName qport = new QName("http://EndUserService/","EndUserServiceImplPort");
    EndUserService obj = service.getPort( qport,EndUserService.class );
    obj.register(records);
    System.out.println("Complete!");