简体   繁体   English

用java2wsdl生成的Web服务是否可以包含多个Java类的API?

[英]Could the web service generated with `java2wsdl` include API from more than one Java class?

I am using Axis2 to run a web service. 我正在使用Axis2运行Web服务。 Here is a services.xml file that defines a service: 这是定义服务的services.xml文件:

<service name="XEWS" scope="transportsession" class="com.mc.xews.XEWS">
<messageReceivers>
    <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
    <messageReceiver  mep="http://www.w3.org/2004/08/wsdl/in-out"  class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</messageReceivers>
<parameter name="ServiceClass" locked="false">com.mc.xews.XEWS</parameter>

My problem is that the whole API is located in one single Java file XEWS.java and this class is sent to java2wsdl . 我的问题是整个API都位于一个Java文件XEWS.java并且此类被发送到java2wsdl Is there a way to have more than one class as input to java2wsdl ? 有没有一种方法可以将多个类用作java2wsdl输入? This file is used with WSDL to generate web service. 该文件与WSDL一起使用以生成Web服务。 Right now I use only one class as input to java2wsdl , so this class became huge, since there is many API functions.... that could be nicely grouped in separate classes if I knew how to send more than one file to java2wsdl. 现在,我仅使用一个类作为java2wsdl输入,因此该类变得非常大,因为有许多API函数。...如果我知道如何将多个文件发送到java2wsdl,则可以将它们很好地分组在单独的类中。 JavaDocs documentation generated from this class is also hard to read. 从此类生成的JavaDocs文档也很难阅读。

Could the web service include API from more than one Java class? Web服务是否可以包含多个Java类的API?

Is maybe extra classes option parameter from java2wsdl supposed to be used for this? 是否应该为此使用java2wsdl extra classes选项参数?

In WSDL the largest namespace is the service itself (it's methods are the smallest). 在WSDL中,最大的名称空间是服务本身(它的方法是最小的)。 WSDL doesn't support nested namespaces. WSDL不支持嵌套名称空间。 The most logical mapping between Java and WSDL is the Java Class to the WSDL Service. Java和WSDL之间最逻辑的映射是WSDL服务的Java类。 This is what makes your request to pass multiple Java Classes to get a single WSDL impossible. 这就是使您无法通过多个Java类来获取单个WSDL的请求。 You can always host more than one WSDL but you still have to generate those separately. 您始终可以托管多个WSDL,但是仍然必须分别生成它们。

Quoting the w3c : 引用w3c

Related concrete endpoints are combined into abstract endpoints (services)

There is an IMPORT mechanism to combine WSDLs but this is seen as a single service to the WSDL2Java (or any other SOAP client) so the it would still represent a single service. 有一种IMPORT机制可以组合WSDL,但是这被视为WSDL2Java(或任何其他SOAP客户端)的单一服务,因此它仍将代表单一服务。

If you are worried about the size of the implementation, just look at PayPal's web service . 如果您担心实现的规模,只需查看PayPal的Web服务

No, this is not possible as Axis2 generation tool maps Java class : WSDL as 1:1 in a code-first approach. 不,这是不可能的,因为Axis2生成工具以代码优先方式将Java类:WSDL映射为1:1。 Hypothetically, they could have provided feature to map multiple Java classes to a single WSDL (that would require additional parameters in generation tool). 假设地,他们可能提供了将多个Java类映射到单个WSDL的功能(这将需要在生成工具中添加其他参数)。

Axis2 uses 'extra classes' for additional types - subclasses of original complex types used as input/output. Axis2将“额外类”用于其他类型-原始复杂类型的子类用作输入/输出。

If neat and compact code is the only issue, I would suggest refactoring it the way that only one single class defines all the required operations, but delegates execution to specific & appropriate (multiple) classes. 如果整洁而紧凑的代码是唯一的问题,我建议将其重构为仅一个类定义所有必需的操作,但将执行委派给特定且适当的(多个)类。 This can be considered as an application of a Façade pattern . 这可以看作是Façade模式的一种应用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM