在SoapUI中,我有这个例外
<faultstring>Unmarshalling Error: unexpected element (uri:"http://ws.soap.rd.pl", local:"User"). Expected elements are <{}User></faultstring>
我真的不知道我是否遇到过这个问题。我已尝试在Stack中进行过旅行,但仍无法找到答案。添加了@XmlRootElement,所以我真的很困惑。
请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.soap.rd.pl/" xmlns:ws1="http://ws.soap.rd.pl">
<soapenv:Header/>
<soapenv:Body>
<ws:updateUser>
<!--Optional:-->
<ws1:User>
<ID>?</ID>
<!--Optional:-->
<Imie>?</Imie>
<!--Optional:-->
<Nazwisko>?</Nazwisko>
<!--Optional:-->
<ws1:Adres>
<!--Optional:-->
<id>?</id>
<!--Optional:-->
<Ulica>?</Ulica>
<!--Optional:-->
<Miasto>?</Miasto>
</ws1:Adres>
</ws1:User>
</ws:updateUser>
</soapenv:Body>
</soapenv:Envelope>
我的dto:
@XmlRootElement(name = "Adres", namespace = "http://ws.soap.rd.pl")
@XmlAccessorType(XmlAccessType.FIELD)
public class AddressDto {
@XmlElement(name = "id", required = false)
public Long id;
@XmlElement(name = "Ulica", required = false)
public String street;
@XmlElement(name = "Miasto", required = false)
public String city;
@Override
public String toString() {
return "AddressDto [street=" + street + ", city=" + city + "]";
}
}
和第二个:
@XmlRootElement(name = "User", namespace = "http://ws.soap.rd.pl")
@XmlAccessorType(XmlAccessType.FIELD)
public class UserDto {
@XmlElement(name = "ID")
public long id;
@XmlElement(name = "Imie", required = false)
public String firstName;
@XmlElement(name = "Nazwisko", required = false)
public String lastName;
@XmlElement(name = "Adres", required = false)
public AddressDto addressDto;
@Override
public String toString() {
return "UserDto [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", addressDto=" + addressDto + "]";
}
}
如果您需要我的webService定义:
@WebService(endpointInterface = "userService", serviceName = "userService", name = "userServive")
public interface UserService {
@WebMethod
public void updateUser(@WebParam(name = "User") UserDto user);
}
答案 0 :(得分:1)
尝试将targetNamespace
添加到@WebParam
:
@WebMethod
public void updateUser(
@WebParam(name = "User", targetNamespace = "http://ws.soap.rd.pl")
UserDto user);