Results 1 to 4 of 4
  1. #1
    higashij is offline Member
    Join Date
    Sep 2009
    Posts
    5
    Rep Power
    0

    Default Help with a SOAP message

    I have a servlet that sends a SOAP message to a web service.

    Wondering if it's possible to send a byte array in a SOAP message?

    This is what I originally have, but now I need to send an additional variable that's a byte array.

    Java Code:
    //create connection
          SOAPConnectionFactory soapConnFact = SOAPConnectionFactory.newInstance();
          SOAPConnection connection = soapConnFact.createConnection();
    
          //create message
          MessageFactory msgFact = MessageFactory.newInstance();
          SOAPMessage msg = msgFact.createMessage();
    
          //add SOAP action to header
          MimeHeaders headers = msg.getMimeHeaders();
          headers.addHeader("SOAPAction", "url");
    
          //create objects for message parts
          SOAPPart soapPart = msg.getSOAPPart();
          SOAPEnvelope envelope = soapPart.getEnvelope();
          SOAPBody body = envelope.getBody();
    
          //populate body and create main element and namespace
          SOAPElement bodyElement = body.addChildElement(envelope.createName("Name", "Name", "http://tempuri.org/"));
    
          //add content
          bodyElement.addChildElement("username").addTextNode(_user);
          bodyElement.addChildElement("password").addTextNode(_password);
          bodyElement.addChildElement("xmlStr").addTextNode(_xml);
    
          //save message
          msg.saveChanges();
    Thanks!

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default

    What is the byte array? Is it a file? If so, send it as an attachment.

    The web service itself should be looked on from the point of view of XML. If it looks like a silly thing to stick in XML (and I'd argue that a byte[] is a silly thing to stick in XML in almost every situation) then it's probably an idea to look at attachments.

  3. #3
    higashij is offline Member
    Join Date
    Sep 2009
    Posts
    5
    Rep Power
    0

    Default

    Yes it is a file, but I had to put the content of the file into a byte array since that's what the web service is expecting. And I don't have any control over the web service because a vendor is actually doing that part.

    But just in case, I'll search the forum on how to send it as an attachment.

    Thanks!

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default

    It needs to be setup at both ends.
    Here's the jax-ws doc, scroll down to find the section on SAAJ.

Similar Threads

  1. SOAP Client
    By sathish_2111 in forum Advanced Java
    Replies: 2
    Last Post: 01-27-2010, 07:08 AM
  2. Sending MTOM Attachment through SOAP message
    By suchismitasuchi in forum Advanced Java
    Replies: 0
    Last Post: 01-19-2009, 01:22 PM
  3. Sending [CDATA] element with SOAP message
    By suchismitasuchi in forum Advanced Java
    Replies: 0
    Last Post: 01-19-2009, 10:59 AM
  4. Redirect Page in SOAP Message Handler
    By bluesheeva in forum Advanced Java
    Replies: 0
    Last Post: 12-28-2008, 12:43 PM
  5. Replies: 0
    Last Post: 06-30-2008, 09:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •