Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAXWS中SOAP请求参数的JAXB绑定_Soap_Jaxb_Jax Ws - Fatal编程技术网

JAXWS中SOAP请求参数的JAXB绑定

JAXWS中SOAP请求参数的JAXB绑定,soap,jaxb,jax-ws,Soap,Jaxb,Jax Ws,我的任务是为更新操作编写一个webservice,其中将对象列表传递给该方法 @WebMethod(operationName = "updateObjects", action = "urn:preferences") public boolean updateObjects(List<MyObject> objects){ } 现在是问题陈述。当我查看此方法的SOAP请求(SOAP UI为我生成的)时,该请求如下所示: <soapenv:Envelope xmlns:s

我的任务是为更新操作编写一个webservice,其中将对象列表传递给该方法

@WebMethod(operationName = "updateObjects", action = "urn:preferences")
public boolean updateObjects(List<MyObject> objects){

}
现在是问题陈述。当我查看此方法的SOAP请求(SOAP UI为我生成的)时,该请求如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pref="preferences">
   <soapenv:Header/>
   <soapenv:Body>
      <pref:updateObjects>
         <!--Zero or more repetitions:-->
         <arg0>
            <!--Optional:-->
            <item1>?</item1>
            <!--Optional:-->
            <item2>?</item2>
         </arg0>
      </pref:updateObjects>
   </soapenv:Body>
</soapenv:Envelope>

?
?
但我希望它看起来像下面

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pref="preferences">
   <soapenv:Header/>
   <soapenv:Body>
      <pref:updateObjects>
         <!--Zero or more repetitions:-->
         <Objects>
             <Object>
                <!--Optional:-->
                <item1>?</item1>
                <!--Optional:-->
                <item2>?</item2>
             </Object>
             <Object>
                <!--Optional:-->
                <item1>?</item1>
                <!--Optional:-->
                <item2>?</item2>
             </Object>
         </Objects>  
      </pref:updateObjects>
   </soapenv:Body>
</soapenv:Envelope>  

?
?
?
?

谁能给点建议吗。提前感谢。

您只需在
对象列表中添加一个“包装器”,如下所示:

 @XmlRootElement(name="objects")
 public class MyObjects{

    @XmlElement(name="object")
    List<MyObject> myObjects;
 }

public class MyObject{
    private String item1;
    private String item2;
 }
@WebMethod(operationName = "updateObjects", action = "urn:preferences")
public boolean updateObjects(@WebParam(name = "object") List<MyObject> objects){

}
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pref="preferences">
   <soapenv:Header/>
   <soapenv:Body>
      <pref:updateObjects>
         <!--Zero or more repetitions:-->
         <object>
            <!--Optional:-->
            <item1>?</item1>
            <!--Optional:-->
            <item2>?</item2>
         </object>
      </pref:updateObjects>
   </soapenv:Body>
</soapenv:Envelope>
如果您不想使用“包装器”,可以保留
WebMethod
,但如下所示:

 @XmlRootElement(name="objects")
 public class MyObjects{

    @XmlElement(name="object")
    List<MyObject> myObjects;
 }

public class MyObject{
    private String item1;
    private String item2;
 }
@WebMethod(operationName = "updateObjects", action = "urn:preferences")
public boolean updateObjects(@WebParam(name = "object") List<MyObject> objects){

}
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pref="preferences">
   <soapenv:Header/>
   <soapenv:Body>
      <pref:updateObjects>
         <!--Zero or more repetitions:-->
         <object>
            <!--Optional:-->
            <item1>?</item1>
            <!--Optional:-->
            <item2>?</item2>
         </object>
      </pref:updateObjects>
   </soapenv:Body>
</soapenv:Envelope>
@WebMethod(operationName=“updateObjects”,action=“urn:preferences”)
公共布尔更新对象(@webgram(name=“object”)列表对象){
}
但是您将松开
包装。请求应该是这样的:

 @XmlRootElement(name="objects")
 public class MyObjects{

    @XmlElement(name="object")
    List<MyObject> myObjects;
 }

public class MyObject{
    private String item1;
    private String item2;
 }
@WebMethod(operationName = "updateObjects", action = "urn:preferences")
public boolean updateObjects(@WebParam(name = "object") List<MyObject> objects){

}
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pref="preferences">
   <soapenv:Header/>
   <soapenv:Body>
      <pref:updateObjects>
         <!--Zero or more repetitions:-->
         <object>
            <!--Optional:-->
            <item1>?</item1>
            <!--Optional:-->
            <item2>?</item2>
         </object>
      </pref:updateObjects>
   </soapenv:Body>
</soapenv:Envelope>

?
?

非常感谢ggarcio的快速响应。。有没有一种方法可以不用创建包装器类(通过任何为我们进行包装的注释)就可以做到这一点?对于不同的对象列表,我有8种方法:(