Both service providers and consumers must have the MTOM optimizations enabled. The JAX-WS APIs offer different mechanisms for each type of endpoint.
If you published your service provider using the JAX-WS APIs you enable the runtime's MTOM support as follows:
Access the
Endpointobject for your published service.The easiest way to access the
Endpointobject is when you publish the endpoint. For more information see Publishing a Service in Developing Applications Using JAX-WS.Get the SOAP binding from the
Endpointusing itsgetBinding()method, as shown in Example 16.Example 16. Getting the SOAP Binding from an Endpoint
// Endpoint ep is declared previously SOAPBinding binding = (SOAPBinding)ep.getBinding();
You must cast the returned binding object to a
SOAPBindingobject to access the MTOM property.Set the binding's MTOM enabled property to
trueusing the binding'ssetMTOMEnabled()method, as shown in Example 17.
To MTOM enable a JAX-WS consumer you must do the following:
Cast the consumer's proxy to a
BindingProviderobject.![[Tip]](imagesdb/tip.gif)
Tip For information on getting a consumer proxy see Developing a Consumer Without a WSDL Contract in Developing Applications Using JAX-WS or Developing a Consumer From a WSDL Contract in Developing Applications Using JAX-WS.
Get the SOAP binding from the
BindingProviderusing itsgetBinding()method, as shown in Example 18.Example 18. Getting a SOAP Binding from a
BindingProvider// BindingProvider bp declared previously SOAPBinding binding = (SOAPBinding)bp.getBinding();
Set the bindings MTOM enabled property to
trueusing the binding'ssetMTOMEnabled()method, as shown in Example 19.








