问题
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.
targetNamespace="http://spring.io/guides/gs-producing-web-service" elementFormDefault="qualified">
I have also created the service endpoint below.
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;
}
}
And configured the bean like this.
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"));
}
}
After deploying the WAR file into tomcat server i am able to see the WSDL at http://localhost:8080/Demo2-0.0.1-SNAPSHOT/ws/countries.wsdl which looks like this.
I am able to see the WSDLon the server but unable to find the service endpoint to send the SOAP request. I refereed several tutorials but was unable to figure out the endpoint. Hitting at http://localhost:8080/Demo2-0.0.1-SNAPSHOT/ws/ returns a 405 error. Please help me out on this.
回答1:
Getting a 405 (Method not Allowed) error code when accessing a SOAP service with a browser (i.e. via a GET) is actually correct behavior: all SOAP HTTP access is done via a POST, not a GET.
You can try pointing a SOAP client at the WSDL ( SoapUI for example), and see if that works instead.
回答2:
Probably you would have already solved it but in case not, if you send SOAP request in SOAP UI to http://localhost:8080/Demo2-0.0.1-SNAPSHOT/ws/ it should respond back as this is the location URI that has been set in your Web Service Configuration.
来源:https://stackoverflow.com/questions/27198987/soap-webservice-endpoint-from-wsdl