使用Complex对象作为参数和返回类型,使用JBossWS创建Web服务和客户端

问题描述:

我正在使用JBoss 5.1.0GA开发WebService和Client. JBossWs堆栈已经预装了我下载的二进制文件,据我了解,它是JBossWs 3.1.2GA

I am developing a WebService and Client for it using JBoss 5.1.0GA. The JBossWs stack was already preinstalled with the binary that I downloaded and as I understand it is JBossWs 3.1.2GA

我已经使用此设置开发了一个Web服务,并且还成功创建了一个客户端.这就是我所拥有的.

I have developed a web service using this setup and have also created a client successfully. This is what I have.

作为战争文件部署的pojo Web服务.

A pojo web service deployed as a war file.

@WebService
public class Service{
    @WebMethod
    public CompleObj getConfiguration() {
        CompleObj oConf = new CompleObj ();
        for (int i = 0; i < 10; i++) {
            NestObj oInst = new BOpRepoInstance("Val1", "Val2", "Val3", "Val4");
            oConf.addRepoInstance(oInst);
        }
        return oConf;
    }
}

在这里

CompleObj =>是一个复杂对象,具有NestObj类型的列表.它的 getter/setter,toString和其他一些方法.

CompleObj => is a Complex Object that has a list of type NestObj. Its getter/setters, toString and some other methods.

NextObj =>具有4个类型为String的变量.它的getter/setter, toString,hashCode,equals和其他一些方法.

NextObj => has 4 variables of Type String. Its getter/setters, toString, hashCode, equals and some other methods.

已成功部署此Web服务.

Got this web service deployed successfully.

后来使用eclipse向导创建了一个客户端,用于使用WSDL文档生成Web Service客户端.它还创建了一个示例客户端文件,该文件将调用Web服务并获取返回值.这也像一种魅力.

Later created a client using the eclipse wizard for generating Web Service Client using WSDL document. It also created a sample client file which would call the webservice and fetch the return value. This also worked like a charm.

现在,我的问题是,当eclipse为客户端生成存根时,它为CompleObj和NestObj创建了类.这些类仅具有变量及其获取器/设置器(这是有意义的,因为它们是从WSDL文档生成的).因此,我松了很多其他方法,包括toString,hasCode,equals等,这些方法我也想在客户端使用.

Now my problem is, when eclipse generated stubs for clients it created classes for CompleObj and NestObj. These classes only has the variables and its getters/setters (this make sense as these are being generated from WSDL doc). Thus i loose a lot of other methods that includes toString, hasCode, equals etc, which I want to use at the Client side as well.

现在,我该如何直接使用WebService项目中定义的实际类文件,并避免客户端使用生成的文件.我可以为客户端项目以.jar二进制文件的形式提供类文件,但我真的不知道该如何实现.

Now how can I make use of the actual class files defined in the WebService project directly and avoid the client to use the generated ones. I can provide the class files as .jar binary for the Client project, I cant really get how to achieve this.

另一个问题是,Web服务位置直接嵌入到存根中,我该怎么做才能将Web服务位置作为调用代码的参数的一部分传递?

Another question is, the web service location is embedded in the stubs directly, what can i do to have the webservice location passed as part of the argument to the invocation code?

  1. 在客户端生成的类只是放置 持有人,它不是您自己的课程的反序列化版本,当您 调用用于将对象携带到服务器的服务,然后 JBOOSWS将JAXB映射到实际的类.那么你 不能使自己的类在客户端使用 尽管它们看起来一样.

  1. The classes which are generated in the client side are just place holders it is not deserilized version of your own classes,When you invoke the service it is used to carry your object to server then the JBOOSWS will do the JAXB mapping to the actual classes. So you can not make the your own classes to be used in the client side though they are look same.

URL将在存根代码中固定,因为在eclipse中生成WS客户端的第一个 您必须提供的是WSDL URL,然后eclipse会生成 客户代码,因此生成的代码特定于WSDL 您提供的.如果您想动态传递WSDL,那么您 需要具有自己的代码以通过传递来生成客户端存根 使用任何WSDLtoJAVA或任何其他实用程序的WSDL URL.

URL will be fixed in the stub code, since in eclipse while generating WS client the first thing you must provide is, the WSDL URL,then eclipse will generate the client code accordingly,so generated code is specific to the WSDL you provided. If you want to pass the WSDL dynamically,then you need to have your own code to generate the client stubs by passed WSDL URL using any WSDLtoJAVA or any other utility.