2017-09-14 39 views
0

場景:我必須調用基於WSDL的webService並解析其響應。 問題:我有更新SOAPMessage SOAP標頭的問題& SOAP Body或SOAP Enevelope,我可以使用WSimport工具生成的類創建它。使用SOAPHeader類更新SOAPMessage頭文件java

我已經使用WSimport工具爲提供的wsdl生成了java類。生成了很多類,其中我發現有一個類有創建SOAP Header,Body和其他細節的類,如shown in the picture。我的問題是,當我從提供的類生成我的soapbody和頭時,我無法將其添加到SOAP消息,我想發佈到Web服務以獲得響應。有什麼方法需要創建以生成SOAP消息?

{ 

    Body mySoapBody = new Body(); 
    Header mySoapHeader = new Header(); 

    Envelope mySoapEnevelope = new Envelope(); 

    //Generate SOAP Body 
    mySoapBody.getAny().add(objofIdentifyCustomerClass); 
    //Generate SOAP Header 
    mySoapHeader.getAny().add(emfHeader); 
    //Generate SOAP Enevelope 
    mySoapEnevelope.setBody(mySoapBody); 
    mySoapEnevelope.setHeader(mySoapHeader); 

    //This is an Issue, Cant add generated Header to the SOAP Message 
    SOAPMessage soapMsg= MessageFactory.newInstance().createMessage(); 

    //MessageFactory factory = MessageFactory.newInstance(); 
    //SOAPMessage message = factory.createMessage(); 

    soapMsg.getSOAPBody().addDocument(getRE02XMLBodyMsg(ciscoRE02Request)); 

    // How to add/update SOAP Header in the SOAPMessage ???? 

} 

回答