简体   繁体   中英

Java - How to send byte array on Soap Request?

I was wondering if it is possible to send a byte[] over the Soap Request. Is it? If so, how can i do it using javax.xml.soap.*?

I only know how to do it sending strings.

private static SOAPMessage createSOAPRequest() throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();


    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("ws", "http://www.qwert.com.ar/");

    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("ronkMotor", "ws");
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("file");

    //How to add byte[] here?
    //soapBodyElem1.addTextNode("mutantninja@gmail.com");

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

    soapMessage.saveChanges();

    soapMessage.writeTo(System.out);

    return soapMessage;
}

The ws signature is:

@WebMethod(operationName = "ronkNow", action = "urn:rs")
Response ronkNow(@WebParam(name = "file")byte[] data);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM