2014-11-29 21 views
1

저는 SOAP 웹 서비스에 익숙하지 않으므로 튜토리얼 중 하나를 참조하여 Spring을 사용하여 SOAP 웹 서비스를 작성하십시오. . 나는 이처럼 보이는 xsd에서 wsdl을 만들었다.WSDL의 SOAP webservice 끝점

<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"> 

    <xs:element name="getCountryRequest"> 
     <xs:complexType> 
      <xs:sequence> 
       <xs:element name="name" type="xs:string"/> 
      </xs:sequence> 
     </xs:complexType> 
    </xs:element> 

    <xs:element name="getCountryResponse"> 
     <xs:complexType> 
      <xs:sequence> 
       <xs:element name="country" type="tns:country"/> 
      </xs:sequence> 
     </xs:complexType> 
    </xs:element> 

    <xs:complexType name="country"> 
     <xs:sequence> 
      <xs:element name="name" type="xs:string"/> 
      <xs:element name="population" type="xs:int"/> 
      <xs:element name="capital" type="xs:string"/> 
      <xs:element name="currency" type="tns:currency"/> 
     </xs:sequence> 
    </xs:complexType> 

    <xs:simpleType name="currency"> 
     <xs:restriction base="xs:string"> 
      <xs:enumeration value="GBP"/> 
      <xs:enumeration value="EUR"/> 
      <xs:enumeration value="PLN"/> 
     </xs:restriction> 
    </xs:simpleType> 
</xs:schema> 

또한 아래 서비스 끝점을 만들었습니다.

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; 
    } 
} 

이렇게 bean을 구성하십시오.

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")); 
    } 
} 

바람둥이 서버에 WAR 파일을 배포 한 후 나는 다음과 같습니다 http://localhost:8080/Demo2-0.0.1-SNAPSHOT/ws/countries.wsdl에서 WSDL을 볼 수 있어요.

<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"> 
<wsdl:types> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://spring.io/guides/gs-producing-web-service"> 
<xs:element name="getCountryRequest"> 
<xs:complexType> 
<xs:sequence> 
<xs:element name="name" type="xs:string"/> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 
<xs:element name="getCountryResponse"> 
<xs:complexType> 
<xs:sequence> 
<xs:element name="country" type="tns:country"/> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 
<xs:complexType name="country"> 
<xs:sequence> 
<xs:element name="name" type="xs:string"/> 
<xs:element name="population" type="xs:int"/> 
<xs:element name="capital" type="xs:string"/> 
<xs:element name="currency" type="tns:currency"/> 
</xs:sequence> 
</xs:complexType> 
<xs:simpleType name="currency"> 
<xs:restriction base="xs:string"> 
<xs:enumeration value="GBP"/> 
<xs:enumeration value="EUR"/> 
<xs:enumeration value="PLN"/> 
</xs:restriction> 
</xs:simpleType> 
</xs:schema> 
</wsdl:types> 
<wsdl:message name="getCountryRequest"> 
<wsdl:part element="tns:getCountryRequest" name="getCountryRequest"></wsdl:part> 
</wsdl:message> 
<wsdl:message name="getCountryResponse"> 
<wsdl:part element="tns:getCountryResponse" name="getCountryResponse"></wsdl:part> 
</wsdl:message> 
<wsdl:portType name="CountriesPort"> 
<wsdl:operation name="getCountry"> 
<wsdl:input message="tns:getCountryRequest" name="getCountryRequest"></wsdl:input> 
<wsdl:output message="tns:getCountryResponse" name="getCountryResponse"></wsdl:output> 
</wsdl:operation> 
</wsdl:portType> 
<wsdl:binding name="CountriesPortSoap11" type="tns:CountriesPort"> 
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
<wsdl:operation name="getCountry"> 
<soap:operation soapAction=""/> 
<wsdl:input name="getCountryRequest"> 
<soap:body use="literal"/> 
</wsdl:input> 
<wsdl:output name="getCountryResponse"> 
<soap:body use="literal"/> 
</wsdl:output> 
</wsdl:operation> 
</wsdl:binding> 
<wsdl:service name="CountriesPortService"> 
<wsdl:port binding="tns:CountriesPortSoap11" name="CountriesPortSoap11"> 
<soap:address location="`http://localhost:8080/Demo2-0.0.1-SNAPSHOT/ws/`"/> 
</wsdl:port> 
</wsdl:service> 
</wsdl:definitions> 

나는 SOAP 요청을 보낼 수있는 서비스 엔드 포인트를 찾기 위해 WSDLon에게 서버를 볼 수 있지만 드릴 수 없습니다. 여러 튜토리얼을 참조했지만 끝점을 파악하지 못했습니다. http://localhost:8080/Demo2-0.0.1-SNAPSHOT/ws/에 도달하면 405 오류가 반환됩니다. 이것 좀 도와주세요.

+0

wsdl :''거의 끝 부분에이 라인이 있습니다. 작은 따옴표없이? ' – morgano

+0

예, 스택 오버 플로우로 인해 localhost : 8080을 언급 할 수 없습니다. 같은 것을 강조했다. 내 실제 wsdl 있습니다. 불편을 끼쳐 드려 죄송합니다. –

답변

4

브라우저에서 SOAP 서비스에 액세스 할 때 (즉 GET을 통해) 405 오류가 발생하는 것은 실제로 올바른 동작입니다. 모든 SOAP HTTP 액세스는 GET이 아닌 POST를 통해 수행됩니다.

WSDL (예 : SoapUI)에서 SOAP 클라이언트를 가리키고 대신 해당 클라이언트가 작동하는지 확인할 수 있습니다.

0

아마도 이미 해결했을 것입니다.하지만 SOAP UI에서 SOAP 요청을 http://localhost:8080/Demo2-0.0.1-SNAPSHOT/ws/으로 보내면 웹 서비스 구성에 설정된 위치 URI이므로 응답해야합니다.

+1

나는 당신이 틀렸다고 생각하지 않지만 링크 만 대답한다는 것을 기억한다. 질문에 대답 할지라도 시간과 무관하게 될 수있다. [외부 리소스에 대한 링크는 권장되지만 링크 주위에 컨텍스트를 추가하여 동료 사용자가 아이디어를 얻을 수 있도록하십시오. (http://stackoverflow.com/help/how-to-answer) 목표 사이트가 도달 할 수 없거나 영구적으로 오프라인 상태가되는 경우 항상 중요한 링크의 가장 관련성있는 부분을 인용합니다. " – talegna