How to Call a SOAP Service with WS-Addressing with the JAX-WS Dispatch API

import java.util.Map;

import javax.xml.namespace.QName;
import javax.xml.transform.Source;

public final class JaxWsSample {

  public static void main(final String[] args) throws Exception {
    final Service service = Service.create(new URL("http://localhost/jaxwssample/SampleService?WSDL"), new QName("", "SampleService"));

    final Dispatch dispatch = service.createDispatch(new QName("", "SamplePort"), Source.class /* or JAXBContext */, Mode.PAYLOAD /* or Mode.MESSAGE */, new AddressingFeature() /* enabled and non-required by default */);

    final BindingProvider provider = (BindingProvider) dispatch;

    final Map<String, Object> requestContext = provider.getRequestContext();

    requestContext.put(BindingProvider.SOAPACTION_URI_PROPERTY, ""); /* the action URI of the input message of the operation to be invoked */

    dispatch.invoke(...); /* or invokeAsync or invokeOneWay */


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s