调用Java小程序里面的Web服务方法 [英] Invoke web service method inside Java Applet

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

问题描述

我成功地建造了一个简单的Java Web服务(如例如,您可以参阅建立简单的网页服务

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小程序做了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小程序..)的一切工作正常的code ..当我运行一个简单的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.

谁能帮我在这?

我在这里贴一些code,让你更好地了解什么,我的小程序里面做的:

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可以访问这类资源。因此,你应该签署你的applet 。

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小程序里面的Web服务方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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