Java WebServiceException:未定义的 JBoss 端口类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/657590/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java WebServiceException: Undefined port type with JBoss
提问by MrCelticFox
I am new to Web Services with JBoss. A client is connecting to an EJB3 based Web Service With JBoss AS 5 and JDK 6 using JAX-WS. I am stuck with the following exception:
我是使用 JBoss 的 Web 服务的新手。客户端使用 JAX-WS 连接到基于 EJB3 的 Web 服务和 JBoss AS 5 和 JDK 6。我遇到以下异常:
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 (client is a different project than EJB3 WS):
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:
你好远程.java:
package samples.webservice;
import javax.jws.WebService;
@WebService
//@SOAPBinding(style=SOAPBinding.Style.RPC)
public interface HelloRemote {
public String echo(String input);
}
HelloWorld.java:
你好世界.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;
}
}
回答by anil kumar
add endpointInterface in @WebSevice annotation, if you dont mention endpoint interface give fully qualified portname while using getPort method.
在@WebSevice 注释中添加端点接口,如果您没有提到端点接口,则在使用 getPort 方法时提供完全限定的端口名。
回答by MrCelticFox
In HelloWorld.java, you should change the name = "EndpointInterface"parameter of the @WebServiceannotation to name = "HelloRemote"
在 中HelloWorld.java,您应该name = "EndpointInterface"将@WebService注释的参数更改为name = "HelloRemote"
OR
或者
In BeanWSClient.java, in the getPort(String endpointURI)method, replace
在BeanWSClient.java,在getPort(String endpointURI)方法中,替换
return service.getPort(HelloRemote.class);
with
和
QName port_name = new QName("http://www.openuri.org/2004/04/HelloWorld","HelloWorldPort");
return service.getPort(port_name, HelloRemote.class);
回答by livnat peer
try adding:
-Djava.endorsed.dirs=${jbossHome}/lib/endorsed/
as a vm argument when you execute BeanWSClient. (where jbossHome is of-course your jboss home).
the problem was, as far as i recall, jboss overwritten the sun implementation of WSService, and you need to set your class loading to load the jboss implementation before the sun's implementation.
because sun's implementation is in rt.jar you need to use endorsed lib.
当您执行 BeanWSClient 时,尝试添加:
-Djava.endorsed.dirs=${jbossHome}/lib/endorsed/
作为 vm 参数。(其中 jbossHome 当然是您的 jboss 家)。
问题是,据我所知,jboss 覆盖了 WSService 的 sun 实现,并且您需要将类加载设置为在 sun 实现之前加载 jboss 实现。
因为 sun 的实现是在 rt.jar 中,所以你需要使用认可的库。
回答by livnat peer
Try to use this method:
尝试使用这种方法:
//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();
}
}

