# javax.jws.soap

***

**1. Binding SOAP messages to methods**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    @SOAPBinding(style = SOAPBinding.Style.RPC)
    public void myOperation(@WebParam(name = "param") String param) {
        // ...
    }
}
```

**2. Specifying SOAP message encoding**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    @SOAPBinding(encoding = SOAPBinding.Encoding.LITERAL)
    public void myOperation(@WebParam(name = "param") String param) {
        // ...
    }
}
```

**3. Configuring SOAP header fault**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    @SOAPBinding(fault = {@SOAPFault(faultName = "MyFault", name = "MyFault", namespace = "http://my.namespace/faults")})
    public void myOperation(@WebParam(name = "param") String param) {
        // ...
    }
}
```

**4. Customizing SOAP header**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    @SOAPBinding(headerFault = true)
    public void myOperation(@WebParam(name = "param") String param) {
        // ...
    }
}
```

**5. Disabling SOAP header**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    @SOAPBinding(headerFault = false)
    public void myOperation(@WebParam(name = "param") String param) {
        // ...
    }
}
```

**6. Configuring SOAP message transport**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    @SOAPBinding(transport = SOAPBinding.Transport.HTTP)
    public void myOperation(@WebParam(name = "param") String param) {
        // ...
    }
}
```

**7. Customizing SOAP message version**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    @SOAPBinding(version = SOAPBinding.SOAP12)
    public void myOperation(@WebParam(name = "param") String param) {
        // ...
    }
}
```

**8. Binding SOAP messages to JAX-WS annotations**

```java
@WebService
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL)
public class MyService {

    @WebMethod
    public void myOperation(@WebParam(name = "param") String param) {
        // ...
    }
}
```

**9. Overriding default SOAP message binding**

```java
@WebService(endpointInterface = "my.service.MyService")
@SOAPBinding(style = SOAPBinding.Style.RPC, use = SOAPBinding.Use.LITERAL)
public class MyServiceImpl implements MyService {

    @Override
    public void myOperation(@WebParam(name = "param") String param) {
        // ...
    }
}
```

**10. Configuring SOAP binding programmatically**

```java
BindingProvider bindingProvider = (BindingProvider) port;
Binding binding = bindingProvider.getBinding();
SOAPBinding soapBinding = (SOAPBinding) binding;
soapBinding.setStyle(SOAPBinding.Style.DOCUMENT);
soapBinding.setUse(SOAPBinding.Use.LITERAL);
```

**11. Accessing SOAP message context**

```java
BindingProvider bindingProvider = (BindingProvider) port;
MessageContext context = bindingProvider.getRequestContext();
SOAPMessage soapMessage = (SOAPMessage) context.getMessage();
```

**12. Modifying SOAP message**

```java
BindingProvider bindingProvider = (BindingProvider) port;
MessageContext context = bindingProvider.getRequestContext();
SOAPMessage soapMessage = (SOAPMessage) context.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
// Modify SOAP envelope...
```

**13. Adding SOAP header**

```java
BindingProvider bindingProvider = (BindingProvider) port;
MessageContext context = bindingProvider.getRequestContext();
SOAPMessage soapMessage = (SOAPMessage) context.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPHeader soapHeader = soapEnvelope.addHeader();
// Add header elements...
```

**14. Removing SOAP header**

```java
BindingProvider bindingProvider = (BindingProvider) port;
MessageContext context = bindingProvider.getRequestContext();
SOAPMessage soapMessage = (SOAPMessage) context.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPHeader soapHeader = soapEnvelope.getHeader();
if (soapHeader != null) {
    soapEnvelope.removeHeader(soapHeader);
}
```

**15. Retrieving SOAP header**

```java
BindingProvider bindingProvider = (BindingProvider) port;
MessageContext context = bindingProvider.getRequestContext();
SOAPMessage soapMessage = (SOAPMessage) context.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPHeader soapHeader = soapEnvelope.getHeader();
if (soapHeader != null) {
    // Retrieve header elements...
}
```

**16. Adding SOAP body**

```java
BindingProvider bindingProvider = (BindingProvider) port;
MessageContext context = bindingProvider.getRequestContext();
SOAPMessage soapMessage = (SOAPMessage) context.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPBody soapBody = soapEnvelope.getBody();
// Add body elements...
```

**17. Removing SOAP body**

```java
BindingProvider bindingProvider = (BindingProvider) port;
MessageContext context = bindingProvider.getRequestContext();
SOAPMessage soapMessage = (SOAPMessage) context.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPBody soapBody = soapEnvelope.getBody();
if (soapBody != null) {
    soapEnvelope.removeBody();
}
```

**18. Retrieving SOAP body**

```java
BindingProvider bindingProvider = (BindingProvider) port;
MessageContext context = bindingProvider.getRequestContext();
SOAPMessage soapMessage = (SOAPMessage) context.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPBody soapBody = soapEnvelope.getBody();
if (soapBody != null) {
    // Retrieve body elements...
}
```

**19. Adding SOAP fault**

```java
BindingProvider bindingProvider = (BindingProvider) port;
MessageContext context = bindingProvider.getResponseContext();
SOAPMessage soapMessage = (SOAPMessage) context.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPFault soapFault = soapEnvelope.addFault();
// Add fault details...
```

**20. Removing SOAP fault**

```java
BindingProvider bindingProvider = (BindingProvider) port;
MessageContext context = bindingProvider.getResponseContext();
SOAPMessage soapMessage = (SOAPMessage) context.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPFault soapFault = soapEnvelope.getFault();
if (soapFault != null) {
    soapEnvelope.removeFault();
}
```

**21. Retrieving SOAP fault**

```java
BindingProvider bindingProvider = (BindingProvider) port;
MessageContext context = bindingProvider.getResponseContext();
SOAPMessage soapMessage = (SOAPMessage) context.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPFault soapFault = soapEnvelope.getFault();
if (soapFault != null) {
    // Retrieve fault details...
}
```

**22. Handling SOAP faults**

```java
try {
    // Invoke web service operation...
} catch (WebServiceException e) {
    SOAPFault soapFault = e.getFault();
    // Handle SOAP fault...
}
```

**23. Customizing SOAP fault handler**

```java
public class MyFaultHandler extends DefaultSOAPFaultBuilder {

    @Override
    protected SOAPFault buildFault(Exception e) {
        // Customize SOAP fault handling...
        return super.buildFault(e);
    }
}
```

**24. Configuring SOAP fault handler programmatically**

```java
BindingProvider bindingProvider = (BindingProvider) port;
Binding binding = bindingProvider.getBinding();
SOAPBinding soapBinding = (SOAPBinding) binding;
soapBinding.setHandlerChain(new HandlerChain());
soapBinding.getHandlerChain().addHandler(new MyFaultHandler());
```

**25. Using SOAP headers to pass security credentials**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param) {
        // Get security credentials from SOAP header...
    }
}
```

**26. Using SOAP headers to pass transaction context**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param) {
        // Get transaction context from SOAP header...
    }
}
```

**27. Using SOAP headers to pass custom metadata**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param) {
        // Get custom metadata from SOAP header...
    }
}
```

**28. Using SOAP attachments to send binary data**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process binary data from SOAP attachment...
    }
}
```

**29. Using SOAP attachments to send XML fragments**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process XML fragment from SOAP attachment...
    }
}
```

**30. Using SOAP attachments to send text files**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process text file from SOAP attachment...
    }
}
```

**31. Using SOAP attachments to send images**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process image from SOAP attachment...
    }
}
```

**32. Using SOAP attachments to send audio files**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process audio file from SOAP attachment...
    }
}
```

**33. Using SOAP attachments to send video files**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process video file from SOAP attachment...
    }
}
```

**34. Using SOAP attachments to send archives**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process archive from SOAP attachment...
    }
}
```

**35. Using SOAP attachments to send SOAP messages**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process SOAP message from SOAP attachment...
    }
}
```

**36. Using SOAP attachments to send HTML pages**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process HTML page from SOAP attachment...
    }
}
```

**37. Using SOAP attachments to send JavaScript files**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process JavaScript file from SOAP attachment...
    }
}
```

**38. Using SOAP attachments to send CSS files**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process CSS file from SOAP attachment...
    }
}
```

**39. Using SOAP attachments to send JSON files**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process JSON file from SOAP attachment...
    }
}
```

**40. Using SOAP attachments to send XML schemas**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process XML schema from SOAP attachment...
    }
}
```

**41. Using SOAP attachments to send WSDL documents**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process WSDL document from SOAP attachment...
    }
}
```

**42. Using SOAP attachments to send XSLT stylesheets**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process XSLT stylesheet from SOAP attachment...
    }
}
```

**43. Using SOAP attachments to send POJO objects**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process POJO object from SOAP attachment...
    }
}
```

**44. Using SOAP attachments to send serialized objects**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process serialized object from SOAP attachment...
    }
}
```

**45. Using SOAP attachments to send XML documents**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process XML document from SOAP attachment...
    }
}
```

**46. Using SOAP attachments to send HTML documents**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process HTML document from SOAP attachment...
    }
}
```

**47. Using SOAP attachments to send text documents**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process text document from SOAP attachment...
    }
}
```

**48. Using SOAP attachments to send binary streams**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process binary stream from SOAP attachment...
    }
}
```

**49. Using SOAP attachments to send character streams**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process character stream from SOAP attachment...
    }
}
```

**50. Using SOAP attachments to send SOAP envelopes**

```java
@WebService
public class MyService {

    @WebMethod(operationName = "myOperation")
    public void myOperation(@WebParam(name = "param") String param, @WebParam(name = "attachment") Attachment attachment) {
        // Process SOAP envelope from SOAP attachment...
    }
}
```
