REST does it, So why Attachments with SOAP?

The REST model can easily deal with binary data. Point to the binary data with the resource address, and you can GET or POST it.

So why bother about Attachments with SOAP? Well similar to the reasons for the need for WS-Security. With the WS-* model, you have the ability to compose the specs in the stack. If you want to secure the binary data, then the value of attachments with SOAP comes in to play. Say, the binary data is an invoice or a pay sheet, that you would not want all the people to have a peek. Then you can secure the message with the attachment with WS-Security.

PHP Web services framework has full support for handling WS-Security. Hence the PHP users can also enjoy the benefits of the WS-* stack to the full.

Comments

Unknown said…
i have written sample code for SOAP with attachment as below....

public class SaajClient2 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
System.out.println("sample message");

SOAPConnectionFactory soapConnectionFactory=SOAPConnectionFactory.newInstance();
SOAPConnection connection=soapConnectionFactory.createConnection();


MessageFactory mFactory=MessageFactory.newInstance();
SOAPMessage message=mFactory.createMessage();

SOAPBody body=message.getSOAPBody();
AttachmentPart attachment= message.createAttachmentPart();

String stringContent = "Adms Satyam ::::::::::::";
attachment.setContent(stringContent,"text/plain");
attachment.setContentId("message_id");

message.addAttachmentPart(attachment);

SOAPFactory factory=SOAPFactory.newInstance();
Name bodyName=factory.createName("getSoapMessage","q0","http://satyam.adms.com");
SOAPBodyElement bodyElement=body.addBodyElement(bodyName);
Name name=factory.createName("name");
SOAPElement element=bodyElement.addChildElement(name);
element.addTextNode("adms");
System.out.println(" ");
System.out.println("Request Message ::::");
System.out.println(" ");
message.writeTo(System.out);

URL endpoint=new URL("http://172.27.6.122/SOA/");

SOAPMessage response=connection.call(message, endpoint);
SOAPBody soapBody = response.getSOAPBody();
System.out.println("AAAAAAAAAAAAA-----------------------------------------AAAAA");
response.writeTo(System.out);

connection.close();

}catch(Exception e){
System.out.println(e.getMessage());
}

}

}

*********
giving some problem as follows:
Unable to create SOAP connection factory: Provider com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnectionFactory not found