我正在使用Spring WS来生成SOAP Web服务。我的输入请求为空,请帮助我解决问题,因为试图找出问题已经花费了数小时。 以下是我的代码的简要介绍
wsdl :(子集)
CASE
GetPersonByUserId
<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0"
targetNamespace="http://v4_0.webservice.commonuser.u90.org.com" xmlns:impl="http://v4_0.webservice.commonuser.u90.org.com" xmlns:intf="http://v4_0.webservice.commonuser.u90.org.com" xmlns:tns3="http://beans.v4_0.webservice.commonuser.u90.org.com" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://beans.v4_0.webservice.gsec.commonuser.u90.org.com">
<complexType name="User">
<sequence>
<element name="userId" nillable="true" type="xsd:string"/>
<element name="userType" nillable="true" type="xsd:string"/>
<element name="firstName" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="GetPersonByUserIdIP">
<complexContent>
<extension base="tns3:AttributeRequest">
<sequence>
<element name="userId" nillable="true" type="xsd:string"/>
<element name="userType" nillable="true" type="xsd:string"/>
</sequence>
</extension>
</complexContent>
</complexType>
<complexType name="GetPersonByUserIdOP">
<sequence>
<element name="user" nillable="true" type="tns3:User"/>
</sequence>
</complexType>
<element name="getPersonByUserId">
<complexType>
<sequence>
<element name="getPersonByUserIdIP" nillable="true" type="tns3:GetPersonByUserIdIP"/>
</sequence>
</complexType>
</element>
<element name="getPersonByUserIdResponse">
<complexType>
<sequence>
<element name="getPersonByUserIdReturn" nillable="true" type="tns3:GetPersonByUserIdOP"/>
</sequence>
</complexType>
</element>
<wsdl:message name="getPersonByUserIdRequest">
<wsdl:part element="impl:getPersonByUserId" name="parameters"/>
</wsdl:message>
<wsdl:message name="getOrganizationByUserIdRequest">
<wsdl:part element="impl:getOrganizationByUserId" name="parameters"/>
</wsdl:message>
<wsdl:message name="getPersonListResponse">
<wsdl:part element="impl:getPersonListResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getPersonByUserIdResponse">
<wsdl:part element="impl:getPersonByUserIdResponse" name="parameters"/
</wsdl:message>
<wsdl:operation name="getPersonByUserId">
<wsdl:input message="impl:getPersonByUserIdRequest" name="getPersonByUserIdRequest"/>
<wsdl:output message="impl:getPersonByUserIdResponse" name="getPersonByUserIdResponse"/>
</wsdl:operation>
GetPersonByUseridIP:
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import com.org.u90.unifieduser.webservice.v4_0.beans.GetPersonByUserIdIP;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"getPersonByUserIdIP"
})
@XmlRootElement(name = "getPersonByUserId")
public class GetPersonByUserId
implements Serializable
{
@XmlElement(required = true, nillable = true)
protected GetPersonByUserIdIP getPersonByUserIdIP;
public GetPersonByUserIdIP getGetPersonByUserIdIP() {
return getPersonByUserIdIP;
}
public void setGetPersonByUserIdIP(GetPersonByUserIdIP value) {
this.getPersonByUserIdIP = value;
}
}
Spring WS-Config :(同时具有mvc和Ws)
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "GetPersonByUserIdIP", propOrder = {
"userId",
"userType"
})
public class GetPersonByUserIdIP
extends AttributeRequest
implements Serializable
{
@XmlElement(required = true, nillable = true)
protected String userId;
@XmlElement(required = true, nillable = true)
protected String userType;
public String getUserId() {
return userId;
}
public void setUserId(String value) {
this.userId = value;
}
public String getUserType() {
return userType;
}
public void setUserType(String value) {
this.userType = value;
}
}
服务类别:
public class WebAppInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext) throws ServletException {
XmlWebApplicationContext rootContext = new XmlWebApplicationContext();
rootContext.setConfigLocation("classpath*:config/spring/applicationContext.xml");
servletContext.addListener(new ContextLoaderListener(rootContext));
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.register(WebConfigurer.class);
ServletRegistration.Dynamic dispatcher = servletContext.addServlet(
"Component-dispatcherServlet", new DispatcherServlet(dispatcherContext));
dispatcher.addMapping("/web/*");
MessageDispatcherServlet messageDispatcherServlet = new MessageDispatcherServlet();
messageDispatcherServlet.setApplicationContext(rootContext);
messageDispatcherServlet.setTransformWsdlLocations(true);
ServletRegistration.Dynamic dessageDispatcher = servletContext.addServlet("MessageDispatcherServlet",
messageDispatcherServlet);
dessageDispatcher.addMapping("/WS/40/*");
}
}
@Bean(name="cus")
public Wsdl11Definition defaultWsdl11Definition() {
SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
wsdl11Definition.setWsdl(new ClassPathResource("/WEB-INF/wsdl/CommonUserWS.wsdl"));
return wsdl11Definition;
}
来自上述类的GetPersonByUserIdIP-requestpayload为空
以下是我发送的示例请求:
@Endpoint
public class CommonUserWS {
private static final String NAMESPACE_URI = "http://v4_0.webservice.commonuser.u90.org.com";
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getPersonByUserId")
@ResponsePayload
public JAXBElement<GetPersonByUserIdOP> getPersonByUserId(@RequestPayload GetPersonByUserIdIP getPersonByUserIdIP)
throws ContextException {
final GetPersonByUserIdOP output = new GetPersonByUserIdOP();
JAXBElement<GetPersonByUserIdOP> jaxbElement = null;
try {
String userType = getPersonByUserIdIP.getUserType();
String userId = getPersonByUserIdIP.getUserId();
// impl logic
QName qname = new QName("getPersonByUserId");
jaxbElement = new JAXBElement<GetPersonByUserIdOP>(qname, GetPersonByUserIdOP.class, output);
} catch (ContextException e) {
throw e;
}
return jaxbElement;
}
}
我遇到以下错误:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v4="http://v4_0.webservice.commonuser.u90.org.com" xmlns:bean="http://beans.v4_0.webservice.commonuser.u90.org.com">
<soapenv:Header/>
<soapenv:Body>
<bean:getPersonByUserId>
<bean:getPersonByUserIdIP>
<!--1 or more repetitions:-->
<bean:attribute>name</bean:attribute>
<bean:attribute>address</bean:attribute>
<bean:userId>hx52301</bean:userId>
<bean:userType/>
</bean:getPersonByUserIdIP>
</bean:getPersonByUserId>
</soapenv:Body>
</soapenv:Envelope>
感谢您的帮助,我们将不胜感激。
答案 0 :(得分:0)
通过查看您的@RequestPayload,主体应以getPersonByUserIdIP而不是getPersonByUserId开始?
rect