我想通过自动生成wsdl文件来学习spring-ws,我知道这是很多教程,我试过它们,我最喜欢的例子是:
它运作良好,但我试图根据我的需要调整解决方案,它不起作用,我不知道为什么,这对你来说是个问题,这里有什么问题?
我被改变了:
我生成的wsdl文件没有wsdl:operation标签(应该在PortType标签中)......
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch="http://localhost:8080/ws/schema/oss" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost:8080/ws/schema/oss" targetNamespace="http://localhost:8080/ws/schema/oss">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://localhost:8080/ws/schema/oss" version="1.0">
<xs:complexType name="deliverShortMessageRequest">
<xs:sequence>
<xs:element minOccurs="0" name="parameters">
<xs:complexType>
<xs:sequence>
<xs:element name="sms" type="tns:deliverShortMessage"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="deliverShortMessageResponse">
<xs:sequence>
<xs:element name="deliverShortMessageReturn" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="deliverShortMessage">
<xs:sequence>
<xs:element minOccurs="0" name="sms" type="tns:smsMessage"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="smsMessage">
<xs:sequence>
<xs:element minOccurs="0" name="content" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:portType name="SubscriptionPort"></wsdl:portType>
<wsdl:binding name="SubscriptionPortSoap11" type="tns:SubscriptionPort">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
</wsdl:binding>
<wsdl:service name="SubscriptionPortService">
<wsdl:port binding="tns:SubscriptionPortSoap11" name="SubscriptionPortSoap11">
<soap:address location="/"/>
</wsdl:port>
</wsdl:service>
schema.xml中
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="qualified"
targetNamespace="http://localhost:8080/ws/schema/oss"
xmlns:tns="http://localhost:8080/ws/schema/oss">
<xs:complexType name="deliverShortMessageRequest">
<xs:sequence>
<xs:element name="parameters" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="sms" type="tns:deliverShortMessage"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="deliverShortMessageResponse">
<xs:sequence>
<xs:element name="deliverShortMessageReturn" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="deliverShortMessage">
<xs:sequence>
<xs:element name="sms" type="tns:smsMessage" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="smsMessage">
<xs:sequence>
<xs:element name="content" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
我的简单端点类:
@Endpoint
public class MessageEndpoint {
private static final String NAMESPACE_URI = "http://localhost:8080/ws/schema/oss";
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "DeliverShortMessageRequest")
@ResponsePayload
public DeliverShortMessageResponse deliverShortMessage(@RequestPayload DeliverShortMessageRequest deliverShortMessageRequest) {
System.out.println("deliverShortMessage " + deliverShortMessageRequest);
DeliverShortMessageResponse result = new DeliverShortMessageResponse();
result.setDeliverShortMessageReturn(true);
return result;
}
}
spring-ws config:
<sws:annotation-driven />
<sws:interceptors>
<bean id="validatingInterceptor" class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor"
p:schema="/WEB-INF/schema.xsd"
p:validateRequest="true"
p:validateResponse="true"/>
<bean id="loggingInterceptor" class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"/>
</sws:interceptors>
<sws:dynamic-wsdl id="subscription"
portTypeName="SubscriptionPort"
locationUri="/"
targetNamespace="http://localhost:8080/ws/schema/oss">
<sws:xsd location="/WEB-INF/schema.xsd"/>
</sws:dynamic-wsdl>
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"
p:contextPath="org.krams.tutorial.model"/>
<bean id="marshallingPayloadMethodProcessor" class="org.springframework.ws.server.endpoint.adapter.method.MarshallingPayloadMethodProcessor">
<constructor-arg ref="jaxbMarshaller"/>
<constructor-arg ref="jaxbMarshaller"/>
</bean>
<bean id="defaultMethodEndpointAdapter" class="org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter">
<property name="methodArgumentResolvers">
<list>
<ref bean="marshallingPayloadMethodProcessor"/>
</list>
</property>
<property name="methodReturnValueHandlers">
<list>
<ref bean="marshallingPayloadMethodProcessor"/>
</list>
</property>
</bean>
当我搜索答案为什么会发生这种情况时,我发现了像: Spring-WS generates WSDL without operations Spring-WS WSDL Generation Problem但正如您所见,我的请求和响应对象具有请求和响应后缀
你有什么想法我忘记了吗?为什么在wsdl我没有操作标签?看起来他没有看到Endpoint操作或者有一些字母不匹配
答案 0 :(得分:0)
问题是你的xsd错了。您应该将复杂类型包装在元素中。
<xs:element name="deliverShortMessageRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="parameters" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="sms" type="tns:deliverShortMessage"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element />
<xs:element name="deliverShortMessageResponse">
<xs:complexType >
<xs:sequence>
<xs:element name="deliverShortMessageReturn" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>