# javax.xml.ws.wsaddressing

***

**1. Setting the Endpoint Address**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // ...
    }
}

// In the client:
MyService service = new MyServiceImpl();
BindingProvider bp = (BindingProvider) service;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:8080/myService");
```

**2. Using the WSA Destination**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA destination from the message context
        WSDestination destination = (WSDestination) messageContext.get(MessageContext.WS_ADDRESSING_DESTINATION);
        String destinationAddress = destination.getAddress().getValue();
        // ...
    }
}
```

**3. Setting the FaultTo Address**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        try {
            // ...
        } catch (Exception e) {
            // Get the WSA fault to address from the message context
            WSEndpointReference faultTo = (WSEndpointReference) messageContext.get(MessageContext.WS_ADDRESSING_FAULT_TO);
            // Send the fault to the specified address
            // ...
        }
    }
}
```

**4. Using the WSA Action**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    @WebResult(name = "result")
    public String myMethod(@WebParam(name = "arg") String arg) {
        // Get the WSA action from the message context
        WSAction action = (WSAction) messageContext.get(MessageContext.WS_ADDRESSING_ACTION);
        String actionValue = action.getValue();
        // ...
    }
}
```

**5. Setting the RelatesTo Attribute**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod(@WebParam(name = "messageID") String messageID) {
        // Get the WSA message ID from the message context
        WSEndpointReference relatesTo = (WSEndpointReference) messageContext.get(MessageContext.WS_ADDRESSING_RELATES_TO);
        relatesTo.getMessageIDs().add(messageID);
        // ...
    }
}
```

**6. Using the Message ID**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA message ID from the message context
        String messageID = (String) messageContext.get(MessageContext.WS_ADDRESSING_MESSAGE_ID);
        // ...
    }
}
```

**7. Setting the ReplyTo Address**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA reply to address from the message context
        WSEndpointReference replyTo = (WSEndpointReference) messageContext.get(MessageContext.WS_ADDRESSING_REPLY_TO);
        // ...
    }
}
```

**8. Using the WSA Reference Properties**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA reference properties from the message context
        Map<String, String> referenceProperties = (Map<String, String>) messageContext.get(MessageContext.WS_ADDRESSING_REFERENCE_PROPERTIES);
        // ...
    }
}
```

**9. Setting the WSA To Header**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA to header from the message context
        WSEndpointReference to = (WSEndpointReference) messageContext.get(MessageContext.WS_ADDRESSING_TO);
        // ...
    }
}
```

**10. Using the WSA Fault RelatesTo**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA fault relates to from the message context
        WSEndpointReference faultRelatesTo = (WSEndpointReference) messageContext.get(MessageContext.WS_ADDRESSING_FAULT_RELATES_TO);
        // ...
    }
}
```

**11. Setting the WSA From Header**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA from header from the message context
        WSEndpointReference from = (WSEndpointReference) messageContext.get(MessageContext.WS_ADDRESSING_FROM);
        // ...
    }
}
```

**12. Using the WSA Fault To Header**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA fault to header from the message context
        WSEndpointReference faultTo = (WSEndpointReference) messageContext.get(MessageContext.WS_ADDRESSING_FAULT_TO);
        // ...
    }
}
```

**13. Setting the WSA ReplyTo Header**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA reply to header from the message context
        WSEndpointReference replyTo = (WSEndpointReference) messageContext.get(MessageContext.WS_ADDRESSING_REPLY_TO);
        // ...
    }
}
```

**14. Using the WSA Fault**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA fault from the message context
        WSFault fault = (WSFault) messageContext.get(MessageContext.WS_ADDRESSING_FAULT);
        // ...
    }
}
```

**15. Setting the WSA ReferenceParameters**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA reference parameters from the message context
        List<ReferenceParameter> referenceParameters = (List<ReferenceParameter>) messageContext.get(MessageContext.WS_ADDRESSING_REFERENCE_PARAMETERS);
        // ...
    }
}
```

**16. Using the WSA MessageID**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA message ID from the message context
        String messageID = (String) messageContext.get(MessageContext.WS_ADDRESSING_MESSAGE_ID);
        // ...
    }
}
```

**17. Setting the WSA Action**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA action from the message context
        WSAction action = (WSAction) messageContext.get(MessageContext.WS_ADDRESSING_ACTION);
        // ...
    }
}
```

**18. Using the WSA ReplyTo**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA reply to from the message context
        WSEndpointReference replyTo = (WSEndpointReference) messageContext.get(MessageContext.WS_ADDRESSING_REPLY_TO);
        // ...
    }
}
```

**19. Setting the WSA FaultTo**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA fault to from the message context
        WSEndpointReference faultTo = (WSEndpointReference) messageContext.get(MessageContext.WS_ADDRESSING_FAULT_TO);
        // ...
    }
}
```

**20. Using the WSA RelatesTo**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA relates to from the message context
        List<WSEndpointReference> relatesTo = (List<WSEndpointReference>) messageContext.get(MessageContext.WS_ADDRESSING_RELATES_TO);
        // ...
    }
}
```

**21. Setting the WSA From**

```java
@WebService(endpointInterface = "com.example.MyService")
public class MyServiceImpl implements MyService {
    @WebMethod
    public void myMethod() {
        // Get the WSA from from the message context
        WSEndpointReference from = (WSEndpointReference) messageContext.get(MessageContext.WS_ADDRESSING_FROM);

```
