[[creating-a-soap-web-service]]
= Creating a SOAP Web Service

In this example, we will create an application to manage a list of fruits.

First, let's create the `Fruit` bean as follows:

[source,java]
----
package org.acme.cxf;

import java.util.Objects;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlType(name = "Fruit")
@XmlRootElement
public class Fruit {

    private String name;

    private String description;

    public Fruit() {
    }

    public Fruit(String name, String description) {
        this.name = name;
        this.description = description;
    }

    public String getName() {
        return name;
    }

    @XmlElement
    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    @XmlElement
    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof Fruit)) {
            return false;
        }

        Fruit other = (Fruit) obj;

        return Objects.equals(other.getName(), this.getName());
    }

    @Override
    public int hashCode() {
        return Objects.hash(this.getName());
    }
}
----

Now, create the `org.acme.cxf.FruitWebService` class as follows:

[source,java]
----
package org.acme.cxf;

import java.util.Set;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface FruitWebService {

    @WebMethod
    Set<Fruit> list();

    @WebMethod
    Set<Fruit> add(Fruit fruit);

    @WebMethod
    Set<Fruit> delete(Fruit fruit);
}
----

Then, create the `org.acme.cxf.FruitWebServiceImpl` class as follows:

[source,java]
----
package org.acme.cxf;

import java.util.Collections;
import java.util.Set;
import java.util.HashSet;

import javax.jws.WebService;

@WebService(endpointInterface = "org.acme.cxf.FruitWebService")
public class FruitWebServiceImpl implements FruitWebService {

    private Set<Fruit> fruits = Collections.synchronizedSet(new HashSet<>());

    public FruitWebServiceImpl() {
        fruits.add(new Fruit("Apple", "Winter fruit"));
        fruits.add(new Fruit("Pineapple", "Tropical fruit"));
    }

    @Override
    public Set<Fruit> list() {
        return fruits;
    }

    @Override
    public Set<Fruit> add(Fruit fruit) {
        fruits.add(fruit);
        return fruits;
    }

    @Override
    public Set<Fruit> delete(Fruit fruit) {
        fruits.remove(fruit);
        return fruits;
    }
}
----

The implementation is pretty straightforward and you just need to define your endpoints using the `application.properties`.

[source,properties]
----
quarkus.cxf.path=/cxf
quarkus.cxf.endpoint."/fruit".implementor=org.acme.cxf.FruitWebServiceImpl
----

The following sample curl command can be used to test your Fruit service.

[source,bash]
----
curl -X POST "http://localhost:8080/cxf/fruit" \
 -H 'Content-Type: text/xml' \
 -H 'SOAPAction:' \
 -d '
 <soapenv:Envelope
 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:cxf="http://cxf.acme.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <cxf:list/>
   </soapenv:Body>
</soapenv:Envelope>'
----

[[wsdl-url]]
== WSDL URL

When using code first development, CXF generates the WSDL for each SOAP web service.  You can access the WSDL by appending `?wsdl` at end of the service URL.

The following sample curl command can be used to grab the generated WSDL.

[source,bash]
----
curl http://localhost:8080/cxf/fruit?wsdl
----

[[soap-annotations]]
== SOAP Annotations

The JAX-WS API provides several annotations that are used to specify metadata for your service definitions.

_List of annotations:_

* `@SOAPBinding`
* `@WebService`
* `@WebMethod`
* `@RequestWrapper`
* `@ResponseWrapper`
* `@WebFault`
* `@Oneway`
* `@WebParam`
* `@WebResult`

If you start from Java code, here is the https://cxf.apache.org/docs/developing-a-service.html#DevelopingaService-JavaFirstDevelopment[documentation of annotations to customize a web service].

[[soap-binding]]
== SOAP Binding

By default, a SOAP 1.1 binding is used. In order to switch to SOAP 1.2 and/or support MTOM, the config `quarkus.cxf.endpoint.key.soap-binding` must be set to one of the following values:

|===
| Binding | Property Value

| SOAP 1.1 | http://schemas.xmlsoap.org/wsdl/soap/http
| SOAP 1.2 | http://www.w3.org/2003/05/soap/bindings/HTTP/
| SOAP 1.1 with MTOM | http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true
| SOAP 1.2 with MTOM | http://www.w3.org/2003/05/soap/bindings/HTTP/?mtom=true


|===


