Java WebServiceException:使用JBoss的未定义端口类型

时间:2009-03-18 09:49:12

标签: java web-services jboss

我是JBoss的Web Services新手。客户端正在连接到基于EJB3的Web Service 使用JBoss AS 5和JDK 6使用JAX-WS。我遇到以下异常:

Exception in thread "main" javax.xml.ws.WebServiceException:
Undefined port type: {http://webservice.samples/}HelloRemote
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:300)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:306)
at javax.xml.ws.Service.getPort(Service.java:161)
at samples.client.BeanWSClient.getPort(BeanWSClient.java:44)
at samples.client.BeanWSClient.main(BeanWSClient.java:35)

BeanWSClient.java(客户端是与EJB3 WS不同的项目):

package samples.client;
import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import samples.webservice.HelloRemote;

public class BeanWSClient {
    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
        String endpointURI ="http://192.168.22.100:8080/SampleWSEJBProject/HelloWorld?wsdl";
        String helloWorld = "Hello world!";
        Object retObj = getPort(endpointURI).echo(helloWorld);
        System.out.println(retObj);
    }

    private static HelloRemote getPort(String endpointURI) throws MalformedURLException  {   
        QName serviceName = new QName("http://www.openuri.org/2004/04/HelloWorld", "HelloWorldService");   
        URL wsdlURL = new URL(endpointURI);   
        Service service = Service.create(wsdlURL, serviceName);   
        return service.getPort(HelloRemote.class);   
    }   

HelloRemote.java:

package samples.webservice;
import javax.jws.WebService; 

@WebService
//@SOAPBinding(style=SOAPBinding.Style.RPC)
public interface HelloRemote  {
    public String echo(String input);
}

HelloWorld.java:

package samples.webservice;

import javax.ejb.Remote;   
import javax.ejb.Stateless;   
import javax.jws.WebMethod;   
import javax.jws.WebService;   
import javax.jws.soap.SOAPBinding;

/**
 * Session Bean implementation class MyBean
 */
@WebService(name = "EndpointInterface", targetNamespace = "http://www.openuri.org/2004/04/HelloWorld", serviceName = "HelloWorldService")
@SOAPBinding(style = SOAPBinding.Style.RPC)
@Remote(HelloRemote.class)
@Stateless
public class HelloWorld implements HelloRemote {
    /**
     * @see Object#Object()
     */
    @WebMethod
    public String echo(String input) {
        return input;
    }
}

4 个答案:

答案 0 :(得分:2)

在@WebSevice注释中添加端点接口,如果在使用getPort方法时没有提到端点接口给出完全限定的端口名。

答案 1 :(得分:2)

HelloWorld.java中,您应该将name = "EndpointInterface"注释的@WebService参数更改为name = "HelloRemote"

BeanWSClient.java中,在getPort(String endpointURI)方法中,替换

return service.getPort(HelloRemote.class);  

QName port_name = new QName("http://www.openuri.org/2004/04/HelloWorld","HelloWorldPort");
return service.getPort(port_name, HelloRemote.class);

答案 2 :(得分:0)

尝试添加:
-Djava.endorsed.dirs = $ {jbossHome} / LIB /认可/
执行BeanWSClient时作为vm参数。 (其中jbossHome当然是你的jboss家) 问题是,据我所知,jboss覆盖了WSService的sun实现,你需要设置类加载以在sun实现之前加载jboss实现。
因为sun的实现是在rt.jar中你需要使用支持的lib。

答案 3 :(得分:-1)

尝试使用此方法:

//inicia classe
public void test(){ 
    String url = "http://localhost:8080/soujava_server/HelloWorld?wsdl";
    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();

    // Create a method instance.
    GetMethod method = new GetMethod(url);

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));

    try {
        // Execute the method.
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
        System.err.println("Method failed: " + method.getStatusLine());
        }

        // Read the response body.
        byte[] responseBody = method.getResponseBody();

        // Deal with the response.
        // Use caution: ensure correct character encoding and is not binary data
        System.out.println(new String(responseBody));

    } catch (HttpException e) {
    System.err.println("Fatal protocol violation: " + e.getMessage());
    e.printStackTrace();
    } catch (IOException e) {
    System.err.println("Fatal transport error: " + e.getMessage());
    e.printStackTrace();
    } finally {
    // Release the connection.
    method.releaseConnection();     
    }       
}