在 Java Applet 中调用 Web 服务方法 [英] Invoke web service method inside Java Applet

查看:26
本文介绍了在 Java Applet 中调用 Web 服务方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成功构建了一个简单的 Java Web 服务(例如您可以参考 "Building简单的网络服务" )

I succesfully builded a simple Java Web Service (as example you can refer to the "Building simple web service" )

在 Eclipse 中使用Java Web 服务代理技术"可以轻松创建 Web 服务客户端.教程中有说明.

In Eclipse is easy to create a web service client by using the "Java Web Service Proxy technique" indicated in the tutorial.

我想运行一个 Java Applet,它执行与 Java 客户端应用程序相同的操作:访问 Web 服务、调用方法并返回结果.

I want to run a Java Applet that do the same things of the java client application: access the web service, invoke the methods and return the results.

当我通过 Eclipse 运行代码时(右键单击>作为 Java Applet 运行......")一切正常......当我在一个简单的 html 页面中运行小程序时,小程序启动但陷入僵局:不抛出异常,进程被阻塞,在创建 MyWebServiceProxy 类的行上不做任何事情,调用默认构造函数.

When i run the code by Eclipse (right click > "run as Java Applet..") everything works fine.. when i run the applet in a simple html page the applet start but goes in deadlock: No exceptions are thrown, and the process is blocked without doing anything on the line that create the MyWebServiceProxy class, invoking the default constructor.

有人可以帮我吗?

我在这里粘贴了一些代码,让您更好地理解我在小程序中的操作:

I paste here some code to Let you understand better what i'm doing inside the applet:

public class SimpleWSApplet extends Applet {

 public void paint(Graphics g)
 {
  String msg = "Applet initialized";
  int i = 1;
  g.drawString(msg, 20, 20*i++);
  
  msg = "Error in applet";
  try {
   Service service = new Service();
   Call call = (Call)service.createCall();
   call.setTargetEndpointAddress("http://localhost:8080/AppletWSTest/services/SimpleWS");
   call.setOperationName(new QName("http://soapinterop.org/", "getMessage"));
   msg = (String)call.invoke(new Object[]{});
  } catch (Exception e) {
   e.printStackTrace();
   msg = "Error: "+e.getMessage();
  }
  g.drawString(msg, 20, 20*i++);
  //g.drawString(executeInvocation(msg), 20, 20*i++);
 }
}

显然我的网络服务被称为SimpleWS";我调用的方法称为getMessage",它不接受任何参数,并返回一个字符串.

Obviously my web service is called "SimpleWS" and the method that i invoke is called "getMessage", it takes no arguments, and returns a String.

请帮帮我..

推荐答案

如您所知,Java 小程序是在沙箱中执行的.默认情况下,applet 不能访问任何 web 资源,除了它们的原始服务器.只有经过签名的小程序才能访问此类资源.因此,您应该签署您的小程序.

As you know, java applets are executed in a sandbox. By default, applets don't have any access to any web resource except from their original servers. Only signed applets can access such kind of resources. Therefore, you should sign your applet.

这篇关于在 Java Applet 中调用 Web 服务方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆