title: SOAP webservice endpoint from WSDL
body: <p>I am new to the SOAP web service and so referenced one of the tutorial to create a SOAP webservice using Spring.  . I have created the wsdl from the xsd that looks like this.</p>
  
  <pre><code>&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://spring.io/guides/gs-producing-web-service"
             targetNamespace="http://spring.io/guides/gs-producing-web-service" elementFormDefault="qualified"&gt;
  
      &lt;xs:element name="getCountryRequest"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element name="name" type="xs:string"/&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
  
      &lt;xs:element name="getCountryResponse"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element name="country" type="tns:country"/&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
  
      &lt;xs:complexType name="country"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="name" type="xs:string"/&gt;
              &lt;xs:element name="population" type="xs:int"/&gt;
              &lt;xs:element name="capital" type="xs:string"/&gt;
              &lt;xs:element name="currency" type="tns:currency"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:simpleType name="currency"&gt;
          &lt;xs:restriction base="xs:string"&gt;
              &lt;xs:enumeration value="GBP"/&gt;
              &lt;xs:enumeration value="EUR"/&gt;
              &lt;xs:enumeration value="PLN"/&gt;
          &lt;/xs:restriction&gt;
      &lt;/xs:simpleType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>I have also created the service endpoint below.</p>
  
  <pre><code>package hello;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.ws.server.endpoint.annotation.Endpoint;
  import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
  import org.springframework.ws.server.endpoint.annotation.RequestPayload;
  import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
  
  import io.spring.guides.gs_producing_web_service.GetCountryRequest;
  import io.spring.guides.gs_producing_web_service.GetCountryResponse;
  
  @Endpoint
  public class CountryEndpoint {
      private static final String NAMESPACE_URI = "http://spring.io/guides/gs-producing-web-service";
  
      private CountryRepository countryRepository;
  
      @Autowired
      public CountryEndpoint(CountryRepository countryRepository) {
          this.countryRepository = countryRepository;
      }
  
      @PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCountryRequest")
      @ResponsePayload
      public GetCountryResponse getCountry(
              @RequestPayload GetCountryRequest request) {
          GetCountryResponse response = new GetCountryResponse();
          response.setCountry(countryRepository.findCountry(request.getName()));
  
          return response;
      }
  }
  </code></pre>
  
  <p>And configured the bean like this.</p>
  
  <pre><code>package hello;
  
  import org.springframework.boot.context.embedded.ServletRegistrationBean;
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.core.io.ClassPathResource;
  import org.springframework.ws.config.annotation.EnableWs;
  import org.springframework.ws.config.annotation.WsConfigurerAdapter;
  import org.springframework.ws.transport.http.MessageDispatcherServlet;
  import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
  import org.springframework.xml.xsd.SimpleXsdSchema;
  import org.springframework.xml.xsd.XsdSchema;
  
  @EnableWs
  @Configuration
  public class WebServiceConfig extends WsConfigurerAdapter {
      @Bean
      public ServletRegistrationBean dispatcherServlet(ApplicationContext applicationContext) {
          MessageDispatcherServlet servlet = new MessageDispatcherServlet();
          servlet.setApplicationContext(applicationContext);
          servlet.setTransformWsdlLocations(true);
          return new ServletRegistrationBean(servlet, "/ws/*");
      }
  
      @Bean(name = "countries")
      public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
          DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
          wsdl11Definition.setPortTypeName("CountriesPort");
          wsdl11Definition.setLocationUri("http://localhost:8080/Demo2-0.0.1-SNAPSHOT/ws/");
          wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
          wsdl11Definition.setSchema(countriesSchema);
          return wsdl11Definition;
      }
  
      @Bean
      public XsdSchema countriesSchema() {
          return new SimpleXsdSchema(new ClassPathResource("countries.xsd"));
      }
  }
  </code></pre>
  
  <p>After deploying the WAR file into tomcat server i am able to see the WSDL at <code>http://localhost:8080/Demo2-0.0.1-SNAPSHOT/ws/countries.wsdl</code> which looks like this.</p>
  
  <pre><code>&lt;wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch="http://spring.io/guides/gs-producing-web-service" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://spring.io/guides/gs-producing-web-service" targetNamespace="http://spring.io/guides/gs-producing-web-service"&gt;
  &lt;wsdl:types&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://spring.io/guides/gs-producing-web-service"&gt;
  &lt;xs:element name="getCountryRequest"&gt;
  &lt;xs:complexType&gt;
  &lt;xs:sequence&gt;
  &lt;xs:element name="name" type="xs:string"/&gt;
  &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;xs:element name="getCountryResponse"&gt;
  &lt;xs:complexType&gt;
  &lt;xs:sequence&gt;
  &lt;xs:element name="country" type="tns:country"/&gt;
  &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;xs:complexType name="country"&gt;
  &lt;xs:sequence&gt;
  &lt;xs:element name="name" type="xs:string"/&gt;
  &lt;xs:element name="population" type="xs:int"/&gt;
  &lt;xs:element name="capital" type="xs:string"/&gt;
  &lt;xs:element name="currency" type="tns:currency"/&gt;
  &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  &lt;xs:simpleType name="currency"&gt;
  &lt;xs:restriction base="xs:string"&gt;
  &lt;xs:enumeration value="GBP"/&gt;
  &lt;xs:enumeration value="EUR"/&gt;
  &lt;xs:enumeration value="PLN"/&gt;
  &lt;/xs:restriction&gt;
  &lt;/xs:simpleType&gt;
  &lt;/xs:schema&gt;
  &lt;/wsdl:types&gt;
  &lt;wsdl:message name="getCountryRequest"&gt;
  &lt;wsdl:part element="tns:getCountryRequest" name="getCountryRequest"&gt;&lt;/wsdl:part&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="getCountryResponse"&gt;
  &lt;wsdl:part element="tns:getCountryResponse" name="getCountryResponse"&gt;&lt;/wsdl:part&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:portType name="CountriesPort"&gt;
  &lt;wsdl:operation name="getCountry"&gt;
  &lt;wsdl:input message="tns:getCountryRequest" name="getCountryRequest"&gt;&lt;/wsdl:input&gt;
  &lt;wsdl:output message="tns:getCountryResponse" name="getCountryResponse"&gt;&lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;/wsdl:portType&gt;
  &lt;wsdl:binding name="CountriesPortSoap11" type="tns:CountriesPort"&gt;
  &lt;soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/&gt;
  &lt;wsdl:operation name="getCountry"&gt;
  &lt;soap:operation soapAction=""/&gt;
  &lt;wsdl:input name="getCountryRequest"&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output name="getCountryResponse"&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;/wsdl:binding&gt;
  &lt;wsdl:service name="CountriesPortService"&gt;
  &lt;wsdl:port binding="tns:CountriesPortSoap11" name="CountriesPortSoap11"&gt;
  &lt;soap:address location="`http://localhost:8080/Demo2-0.0.1-SNAPSHOT/ws/`"/&gt;
  &lt;/wsdl:port&gt;
  &lt;/wsdl:service&gt;
  &lt;/wsdl:definitions&gt;
  </code></pre>
  
  <p><strong>I am able to see the WSDLon the server but unable to find the service endpoint to send the SOAP request.</strong> I refereed several tutorials but was unable to figure out the endpoint. <strong>Hitting at <code>http://localhost:8080/Demo2-0.0.1-SNAPSHOT/ws/</code> returns a 405 error</strong>. Please help me out on this. </p>