我创建了一个运行良好的简单 Web 服务: 接口(interface):
@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloService {
@WebMethod
void sayHello();
}
实现的服务:
@WebService(endpointInterface = "mypackage.HelloService")
public class HelloServiceImpl implements HelloService {
@Override
public void sayHello() {
System.out.println("Hello world");
}
发布者:
public class HelloServicePublisher {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8080/hello", new HelloServiceImpl ());
}
}
当我使用以下客户端代码创建一个普通的 JAVA 项目时,它可以完美运行:
public class Client {
public static void main(String[] args) throws Exception {
URL url = new URL("http://localhost:8080/hello?wsdl");
// 1st argument service URI, refer to wsdl document above
// 2nd argument is service name, refer to wsdl document above
QName qname = new QName("http://server/", "HelloServiceImplService");
Service service = Service.create(url, qname);
HelloService server = service.getPort(HelloService.class);
server.sayHello();
}
}
编译并运行良好。当我将非常相同的客户端代码复制到一个普通的新 CN1 项目中时,我在 service.getPort() 调用中遇到空点异常:
at com.sun.xml.internal.ws.model.RuntimeModeler.getPortTypeName(Unknown Source)
at com.sun.xml.internal.ws.model.RuntimeModeler.getPortTypeName(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at javax.xml.ws.Service.getPort(Unknown Source)
所以问题是:创建 CN1 项目与普通 Java 项目相比到底有什么不同?它确实与代码无关,因为这显然是有效的。 感谢任何提示。
谢谢并致以诚挚的问候
最佳答案
代号一 doesn't support the full Java API它也不支持 JAX。您只能安装 Codename One 支持的库,并且只能使用 javadocs 中提到的 JDK 子集。 。
上面解释了其原因,但总而言之,这是可行性/规模的问题。即使我们去掉所有未使用的内容,完整的 JVM 也将远远超过 50mb,接近 100mb,相比之下,Codename One 接近时钟频率低于 5mb 的 native 操作系统应用程序的效率/大小。
在 networking section of the developer guide我们讨论了几种网络方法,包括 Web 服务向导,它生成一个可以从客户端进行通信的 servlet。这既更快(更高效的通信),又具有更小的代码大小。
关于java - JAX Web 服务无法在 CodenameOne 项目中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43877537/