2013-05-29 34 views
0

我對網絡服務相當陌生,但我明白如何通過SOAP UI工具將簡單參數傳遞給我的方法。 WSDL是基於我的Java代碼生成的。如何將xml文檔傳遞給Java JWS SOAP方法?

這裏是我的方法

@Override 
    @WebMethod 
    public String greetClient(String userName) 
    { 
     return "123 " + userName + "321..."; 
    } 

這裏是在SOAP-UI SOAP信封我的「二合一」的參數執行。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://test.com/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <web:sendGAFile> 
     <arg0>One Two</arg0> 
     </web:sendGAFile> 
    </soapenv:Body> 
</soapenv:Envelope> 

如何將XML文檔傳遞給我的方法?以及如何在SOAP UI中將XML文件添加到我的請求中?

回答

0

對於你的代碼的輸出將會像肥皂下面..

*<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
     <soap:Body> 
      <ns2:giveOutputResponse xmlns:ns2="http://xmltest.sample.org/"> 
      <return>123 One Two321...</return> 
      </ns2:giveOutputResponse> 
     </soap:Body> 
    </soap:Envelope>*  

簡單,如果你想通過XML請嘗試像下面。 您需要使用CDATA,同時發送soap請求.. 除非你會得到解析錯誤.. 至於下面的示例,你將得到輸出與XML .. 你可以在你的代碼中使用分析器,並從XML返回的要求值..

*<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xt="http://xmltest.sample.org/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <xt:giveOutput> 
     <!--Optional:--> 
     <arg0><![CDATA[<?xml version="1.0" encoding="utf-8"?><xml>One Two</xml]]></arg0> 
     </xt:giveOutput> 
    </soapenv:Body> 
</soapenv:Envelope>*