java endpoint wsdl_SOAP webservice endpoint from WSDL

问题

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用JAX-WS API为CXF Web服务设置SOAP操作的值。 在CXF中,您可以使用javax.jws.soap.SOAPBinding注释来指定SOAP操作的值。例如: ```java @WebService @SOAPBinding(style = Style.DOCUMENT, use=Use.LITERAL, parameterStyle=ParameterStyle.WRAPPED) public interface MyService { @WebMethod(operationName="MyOperation") @WebResult(name="MyResult") public String myMethod(@WebParam(name="MyParam") String param); } ``` 在这个例子中,我们为MyService接口的myMethod方法设置了SOAP操作的名称为"MyOperation",并且为返回值设置了SOAP元素的名称"MyResult"。我们还为方法参数设置了SOAP元素的名称"MyParam"。 如果您想要更直接地控制SOAP操作的值,您可以使用javax.xml.ws.soap.SOAPBinding类的soapAction属性。例如: ```java @WebService @SOAPBinding(style = Style.DOCUMENT, use=Use.LITERAL, parameterStyle=ParameterStyle.WRAPPED, soapAction="urn:myMethod") public interface MyService { @WebMethod(operationName="MyOperation") @WebResult(name="MyResult") public String myMethod(@WebParam(name="MyParam") String param); } ``` 在这个例子中,我们为MyService接口设置了SOAP操作的值为"urn:myMethod"。这个值将出现在生成的WSDL文件中,用于指定SOAP操作的名称。 当您使用CXF来发布Web服务时,您可以使用CXF的配置文件来设置SOAP操作的值。例如,在您的CXF配置文件中,您可以添加以下配置: ```xml <jaxws:endpoint xmlns:tns="http://example.com/myservice" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" name="MyServicePort" implementor="com.example.MyServiceImpl" wsdlLocation="classpath:/META-INF/wsdl/MyService.wsdl" serviceName="tns:MyService" endpointName="tns:MyServicePort" > <jaxws:properties> <entry key="soapAction" value="urn:myMethod"/> </jaxws:properties> </jaxws:endpoint> ``` 在这个例子中,我们将SOAP操作的值设置为"urn:myMethod",并将其作为JAX-WS属性传递给CXF。CXF将在生成的WSDL文件中使用这个值来指定SOAP操作的名称。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值