简体   繁体   English

使用JAX-WS创建多个无参数函数

[英]Creating multiple parameterless functions using JAX-WS

I am having trouble creating a Web Service in Java that contains two methods that are parameterless. 我在用Java创建包含两个无参数方法的Web服务时遇到了麻烦。 It's simple to create a single one, but I have not figured out how to get it to work with more than one: 创建一个简单的方法很简单,但是我还没有弄清楚如何使其与多个对象一起使用:

<message name="messageOneRequest" />
<message name="messageOneResponse" />

Would lead to 会导致

public void messageOne() { }

But adding 但是添加

<message name="messageTwoRequest" />
<message name="messageTwoResponse" />

Leads to a "signature" collision. 导致“签名”冲突。 I know the cause of the signature collision, and it's because JAX-WS/JAX-RI are trying to be more efficient with the parameterless method by simply leaving an empty SOAP Body for the incoming message, thus representing a single, parameterless method. 我知道签名冲突的原因,这是因为JAX-WS / JAX-RI试图通过无参数方法简单地为传入消息保留一个空的SOAP Body来提高效率,从而表示一种无参数的方法。 As a side note, I am using Document and not RPC. 附带说明,我使用的是Document,而不是RPC。

Is there a way to allow this? 有办法允许吗? Am I simply missing an attribute? 我是否只是缺少属性?

The goal of my question was to achieve parameterless methods like the following: 我的问题的目标是实现如下的无参数方法:

int someMethod();
ArbitraryObject someOtherMethod();

Even though the two methods do not share the same name, they have a conflicting SOAP body because the incoming SOAP body would be technically identical (most engines seem to supply a blank body for efficiency when there are no arguments, rather than something like <someMethod /> inside of the SOAP body). 即使这两种方法的名称不相同,它们的SOAP主体也会发生冲突,因为传入的SOAP主体在技术上是相同的(大多数引擎似乎在没有参数的情况下为效率提供了空白,而不是像<someMethod />这样的东西。 <someMethod />放在SOAP正文中)。

To make a long story short, there are two simple ways to fix this problem when using Document/Literal. 长话短说,使用文档/文字时,有两种简单的方法可以解决此问题。 The simplest way to work around this issue is to simply give them different parameters. 解决此问题的最简单方法是简单地给它们提供不同的参数。 I originally just supplied a dummy, no-op parameter (called " IgnoredParameter ") to differentiate the two. 我最初只是提供了一个虚拟的无操作参数(称为“ IgnoredParameter ”)来区分两者。 The other way is to provide a unique value for the SOAP Action of each operation that has non-unique parameters. 另一种方法是为每个具有非唯一参数的操作的SOAP Action提供唯一值。 In the case of using wsimport to generate, you also need to supply " -extension " to have it use that feature, or it will simply error out and ignore the presence of the SOAP action. 在使用wsimport生成的情况下,您还需要提供“ -extension ”以使其使用该功能,否则它将简单地出错并忽略SOAP操作的存在。

The drawback to the second approach is that SOAP Action is highly coupled with HTTP (it's used as an HTTP Header). 第二种方法的缺点是SOAP Action与HTTP高度耦合(用作HTTP标头)。 In my case, that was not a problem. 就我而言,这不是问题。 But, obviously that is not always the case especially given that SOAP is meant to be generic. 但是,显然并非总是如此,特别是考虑到SOAP是通用的。

An example binding with this in use (note the actually supplied soapAction versus being commonly blank): 使用中与此绑定的示例(请注意实际提供的soapAction与通常为空白的绑定):

<operation name="someOtherMethod">
    <wsdlsoap:operation soapAction="urn:someOtherMethod"/>
    <input name="someOtherMethodRequest">
        <wsdlsoap:body use="literal"/>
    </input>
    <output name="someOtherMethodResponse">
        <wsdlsoap:body use="literal"/>
    </output>
</operation>

The other, non-conflicted operations/methods can still use soapAction="" . 其他无冲突的操作/方法仍可以使用soapAction=""

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

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