jax-ws Undefined port type with client and server

2019-07-17 21:49发布

问题:

I'm working on a project that is running a webservice in localhost. I used jax-ws for this. When I had a client in the same project as the server, it worked fine. But now I'm trying to create a new client-project but i'm getting this error when i'm trying to run:

Undefined port type: {http://test.main/}MyWSInterface

I've copied the interface in both classes:

package main.test;

import javax.activation.DataHandler; import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style;

@WebService
@SOAPBinding(style = Style.RPC)
public interface MyWSInterface {

@WebMethod public void sendTask(String convertType, String outputFileName, DataHandler dH);

}

I get this error on this line in my main test method:

MyWSInterface dsws = service.getPort(MyWSInterface.class);

Which is the 4th line in this method:

private void runTest() throws MalformedURLException {
    URL url = new URL("http://localhost:8080/MyWS?wsdl");
    QName qname = new QName("http://ws.sender.something.somecompany.com/", "MyWSInterfaceImplService");

    Service service = Service.create(url, qname);
    DocShifterWS dsws = service.getPort(DocShifterWS.class);
    FileDataSource ds = new FileDataSource(new File("C:\\temp\\testinput.txt\\"));
    DataHandler dh = new DataHandler(ds);
    dsws.sendTask("pdf", "something.pdf", dh);

}

回答1:

give endpointIneterface in @WebService annotation in the implementation class, if you dont give endpoint interface, you have to mention fully qualified port name while using getPort method.

MyWSInterface dsws = service.getPort(PortQName,MyWSInterface.class);