java 在 JAX-WS 中重命名参数名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12444138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Renaming the argument name in JAX-WS
提问by user182944
I created a web service using JAX-WS in RSA 7.5 and Websphere 7 using bottom-up approach. When I open the WSDL in SOAP UI, then the arguments section is appearing like this:
我使用自下而上的方法在 RSA 7.5 和 Websphere 7 中使用 JAX-WS 创建了一个 Web 服务。当我在 SOAP UI 中打开 WSDL 时,参数部分显示如下:
<!--Optional-->
<arg0>
<empID>?</empId>
</arg0>
<!--Optional-->
<arg1>
<empName>?</empName>
</arg1>
<!--Optional-->
<arg2>
<empAddress>?</empAddress>
</arg2>
<!--Optional-->
<arg3>
<empCountry>?</empCountry>
</arg3>
The service method takes the above 4 elements as the parameters to return the employee details.
service方法以上述4个元素为参数返回员工详细信息。
1) I want to rename this arg0, arg1, and so on with some valid names.
1) 我想用一些有效的名称重命名这个 arg0、arg1 等等。
2) I want to remove the <!--optional-->
present above the arg tags. (For removing the <!--optional-->
from elements name, I used @XMLElement(required=true)). But I am not sure where exactly to use this annotation in this case :(
2)我想删除<!--optional-->
arg 标签上方的礼物。(为了删除<!--optional-->
from 元素名称,我使用了 @XMLElement(required=true))。但我不确定在这种情况下究竟在哪里使用此注释:(
Please help.
请帮忙。
Regards,
问候,
回答by Logan
You put the @XMLElement(required=true)
above the variables in your class that are being returned from your service. I just learned about that option about a month ago. So right above where you declare empName put the tag and required.
您将@XMLElement(required=true)
上述变量放在从您的服务返回的类中。大约一个月前,我刚刚了解了该选项。所以在你声明 empName 的正上方放置标签和必需的。
To rename the parameters of your service use the @WebParam(name="<name you want in soap>")
in front of each input variable to the service.
要重命名服务的参数,请在服务@WebParam(name="<name you want in soap>")
的每个输入变量前使用。
For example, if you have a service method called get(String name)
it would look something like get(@WebParam(name = "name") String name)
例如,如果您有一个名为的服务方法,get(String name)
它看起来像get(@WebParam(name = "name") String name)
You are correct, now that I read your comment again. The services I support use Objects in the input and output, which is why I put the XMLElement tag in the class of those objects.
你是对的,现在我又看了你的评论。我支持的服务在输入和输出中使用对象,这就是我将 XMLElement 标记放在这些对象的类中的原因。
You need to put the tag in the class that declares your variables that are passed in or returned to the service. If those happen to be declared in your service class that is fine. The main point is that you put that XMLElement tag above the variable declaration, versus putting it on a getter or setter.
您需要将标记放在声明传入或返回到服务的变量的类中。如果这些恰好在您的服务类中声明,那很好。要点是将该 XMLElement 标记放在变量声明之上,而不是放在 getter 或 setter 上。
This tutorial shows some examples of the usage. JAXB tutorial
本教程展示了一些使用示例。JAXB 教程