2014-07-23 96 views
0

我現在有方法的Web服務:如何使用Java Web Service在同一信封中處理多個SOAP請求?

@Override 
@WebResult(Name="OIPResponse") 
public Map<String, Object> getOIP(@WebParam(name = "invoice") String invoiceNumber,@WebParam(name = "part") String partNumber) 

我用它來稱呼它正常的SOAP請求如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:oip="http://oip.mycompany.com/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <oip:getOIP> 
     <invoice>41587182</invoice> 
     <part>9ZF2A5-570</part> 
     </oip:getOIP> 
    </soapenv:Body> 
</soapenv:Envelope> 

和響應是這樣的:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
     <ns2:getOIPResponse xmlns:ns2="http://oip.mycompany.com/"> 
      <OIPResponse> 
       <entry> 
        <key>ERR_CODE</key> 
       </entry> 
       <entry> 
        <key>SELLING_OU</key> 
        <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">null</value> 
       </entry> 
       ... 
      </OIPResponse> 
     </ns2:getOIPResponse> 
    </soap:Body> 
</soap:Envelope> 

我測試過了,它工作正常。現在我想知道如果有一種方法,包括在同一個SOAP信封這樣的多個請求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:oip="http://oip.mycompany.com/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <oip:getOIP> 
     <invoice>41587182</invoice> 
     <part>9ZF2A5-570</part> 
     </oip:getOIP> 
     <oip:getOIP> 
     <invoice>41587183</invoice> 
     <part>9ZF2A5-570</part> 
     </oip:getOIP> 
     <oip:getOIP> 
     <invoice>41587184</invoice> 
     <part>9ZF2A5-570</part> 
     </oip:getOIP> 
     <oip:getOIP> 
     <invoice>41587185</invoice> 
     <part>9ZF2A5-570</part> 
     </oip:getOIP> 
    </soapenv:Body> 
</soapenv:Envelope> 

,並取回這樣的事情:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
     <ns2:getOIPResponse xmlns:ns2="http://oip.mycompany.com/"> 
      <OIPResponse> 
       ... 
      </OIPResponse> 
      <OIPResponse> 
       ... 
      </OIPResponse> 
      <OIPResponse> 
       ... 
      </OIPResponse> 
       ... 
     </ns2:getOIPResponse> 
    </soap:Body> 
</soap:Envelope> 

有沒有辦法做到這一點?

+1

不能修改操作,接受列表,而不是一個單一的發票? – Swapnil

回答

1

我最終創建了一個名爲OIPRequest的POJO,它包含我需要的兩個參數(發票和部件號)和一個新的方法getOIPMultiple,它將OIPRequests數組作爲輸入參數。

import javax.xml.bind.annotation.XmlRootElement; 

@XmlRootElement 
public class OIPRequest { 
    public String invoiceNumber, partNumber; 

    public OIPRequest(String invoice, String part) { 
     invoiceNumber = invoice; 
     partNumber = part; 
    } 

    public OIPRequest() { 
     invoiceNumber = ""; 
     partNumber = ""; 
    } 
} 

這使得該請求是這樣的:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> 
    <Body> 
     <getMultipleOIP xmlns="http://oip.mycompany.com/"> 
      <OIPRequest xmlns=""> 
       <invoiceNumber>41587182</invoiceNumber> 
       <partNumber>9ZF2A5-570</partNumber> 
      </OIPRequest> 
      <OIPRequest xmlns=""> 
       <invoiceNumber>41587182</invoiceNumber> 
       <partNumber>9ZF2A5-570</partNumber> 
      </OIPRequest> 
      <OIPRequest xmlns=""> 
       <invoiceNumber>41587182</invoiceNumber> 
       <partNumber>9ZF2A5-570</partNumber> 
      </OIPRequest> 
     </getMultipleOIP> 
    </Body> 
</Envelope> 
相關問題