2017-10-20 2 views
1

Java로 외부에서 구현 한 SOAP 서비스를 호출하고 싶습니다.Java에서 SOAP 서비스를 호출하려면 어떻게해야합니까?

그러나 다음 오류는 계속 발생합니다. '서버가 HTTP 헤더 SOAPAction의 값을 인식하지 못했습니다'

내 코드에 어떤 문제가 있는지보십시오.

테스트 URL이 'http://example.com/test.asmx?op=tt'

**이 SOAPAction은 무엇

이다 ?????

import javax.xml.soap.*; 

public class SOAPClientSAAJ { 

    // SAAJ - SOAP Client Testing 
    public static void main (String args[]) { 

    String soapEndpointUrl = "http://example.com/test.asmx" ; 
    String soapAction = "http://example.com/tt" ; 

    callSoapWebService (soapEndpointUrl , soapAction) ; 
    } 

private static void createSoapEnvelope (SOAPMessage soapMessage) throws SOAPException { 
    SOAPPart soapPart = soapMessage .getSOAPPart() ; 

    // SOAP Body 
    SOAPBody soapBody = envelope .getBody() ; 
    SOAPElement soapBodyElem1 = soapBody .addChildElement ("element1") ; 
    soapBodyElem11 .addTextNode ("test") ; 
    SOAPElement soapBodyElem2 = soapBody .addChildElement ("element2") ; 
    soapBodyElem12 .addTextNode ("test") ; 

} 

private static void callSoapWebService (String soapEndpointUrl, String soapAction) { 
    try { 
     // Create SOAP Connection 
     SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory . newInstance() ; 
     SOAPConnection soapConnection = soapConnectionFactory .createConnection() ; 

     // Send SOAP Message to SOAP Server 
     SOAPMessage soapResponse = soapConnection .call (createSOAPRequest(soapAction), soapEndpointUrl) ; 

     // Print the SOAP Response 
     System .out . println("Response SOAP Message:"); 
     soapResponse .writeTo (System. out); 
     System .out . println() ; 

     soapConnection .close() ; 
    } catch (Exception e) { 
     System .err . println("\nError occurred while sending SOAP Request to Server!\nMake sure you have the correct endpoint URL and SOAPAction!\n") ; 
     e .printStackTrace() ; 
    } 
} 

    private static SOAPMessage createSOAPRequest (String soapAction) throws Exception { 
    MessageFactory messageFactory = MessageFactory .newInstance() ; 
    SOAPMessage soapMessage = messageFactory .createMessage() ; 

    createSoapEnvelope (soapMessage) ; 

    MimeHeaders headers = soapMessage .getMimeHeaders() ; 
    headers .addHeader ("SOAPAction", soapAction) ; 

    soapMessage .saveChanges() ; 

    /* Print the request message, just for debugging purposes */ 
    System .out . println("Request SOAP Message:"); 
    soapMessage .writeTo (System. out); 
    System .out . println("\n"); 

    return soapMessage ; 
    } 

} 

답변

0

WSDL을 사용할 수 있습니까? eclipse 또는 wsimport를 사용하여 클라이언트를 생성 할 수 있기 때문에 훨씬 쉽습니다.

관련 문제