Note: This page applies to WebSphere Application Server - Express Version 5.0.2 and later only.
The following code fragment could invoke the service described by the example WSDL given in SOAP messages with attachments - writing the WSDL extensions:
import javax.activation.DataHandler; . . . DataHandler dh = new DataHandler(new FileDataSource("myimage.jpg")); WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); WSIFService service = factory.getService("my.wsdl",null,null,"http://mynamespace","abc"); WSIFOperation op = service.getPort().createOperation("MyOperation"); WSIFMessage in = op.createInputMessage(); in.setObjectPart("attch",dh); op.executeInputOnlyOperation(in);
The associated type mapping in the DeploymentDescriptor.xml file depends upon your SOAP server. For example if you use Tomcat with SOAP 2.3, then DeploymentDescriptor.xml contains the following type mapping:
<isd:mappings> <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:x="http://mynamespace" qname="x:datahandler" javaType="javax.activation.DataHandler" java2XMLClassName="org.apache.soap.encoding.soapenc.MimePartSerializer" xml2JavaClassName="org.apache.soap.encoding.soapenc.MimePartSerializer" /> </isd:mappings>
In this case, the backend service is invoked with the following signature:
public void MyOperation(DataHandler dh);
Attachments can also be passed in to WSIF using stubs:
DataHandler dh = new DataHandler(new FileDataSource("myimage.jpg")); WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); WSIFService service = factory.getService("my.wsdl",null,null,"http://mynamespace","abc"); MyInterface stub = (MyInterface)service.getStub(MyInterface.class); stub.MyOperation(dh);
Attachments can also be returned from an operation, but only one attachment can be returned as the return parameter.