WS中重命名参数名称

WS中重命名参数名称

本文介绍了在JAX-WS中重命名参数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用自下而上的方法在RSA 7.5和Websphere 7中使用JAX-WS创建了一个Web服务。当我在SOAP UI中打开WSDL时,参数部分显示如下:

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:

<!--Optional-->
<arg0>
    <empID>?</empId>
</arg0>
<!--Optional-->
<arg1>
    <empName>?</empName>
</arg1>
<!--Optional-->
<arg2>
    <empAddress>?</empAddress>
</arg2>
<!--Optional-->
<arg3>
    <empCountry>?</empCountry>
</arg3>

服务方法将上述4个元素作为返回员工详细信息的参数。

The service method takes the above 4 elements as the parameters to return the employee details.

1)我想用一些有效名称重命名这个arg0,arg1等。

1) I want to rename this arg0, arg1, and so on with some valid names.

2)我想要删除arg标记上方的<! - optional - > 。 (为了从元素名称中删除<! - optional - > ,我使用了@XMLElement(required = true))。但在这种情况下,我不确定在何处使用此注释:(

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 :(

请帮助。

问候,

推荐答案

你把 @XMLElement(required = true)放在上面你的班级中从你的服务中返回的变量。我刚刚在一个月之前就了解了这个选项。所以在你声明empName的地方上面放了标签和必需的。

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.

要重命名服务的参数,请在服务的每个输入变量前面使用 @WebParam(name =< soap in gt>中的名称)

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.

例如,如果您有一个名为的服务方法get(String name),它看起来像 get(@WebParam(name =name)字符串名称)

For example, if you have a service method called get(String name) it would look something like get(@WebParam(name = "name") String name)

你是对的,现在我再次阅读你的评论。我支持的服务在输入和输出中使用对象,这就是我将XMLElement标记放在这些对象的类中的原因。

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标记置于变量声明之上,而不是将它放在getter或setter上。

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.

本教程展示了一些使用示例。

This tutorial shows some examples of the usage. JAXB tutorial

这篇关于在JAX-WS中重命名参数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:35