try
{
MessageFactory mf =
MessageFactory.newInstance();
SOAPMessage sm =
mf.createMessage();
SOAPPart soapPart =
sm.getSOAPPart();
SOAPEnvelope envelope =
soapPart.getEnvelope();
SOAPHeader header =
envelope.getHeader();
SOAPBody body =
envelope.getBody();
URLEndpoint urle =
new
URLEndpoint(options.getURL());
Name bodyName =
envelope.createName("ServiceMethod", "", "urn:Attachment");
javax.xml.soap.SOAPBodyElement gltp = body.addBodyElement(bodyName);
// Add an attachment
(binary attachment)
URL url2 = new File("C:\\foo.class").toURL();
AttachmentPart ap2 =
sm.createAttachmentPart(new
DataHandler(url2));
ap2.setContentType("image");
sm.addAttachmentPart(ap2);
sm.saveChanges();
SOAPMessage result =
conn.call(sm, (Object)urle);
} catch (Exception
e) {
e.printStackTrace();
}