SOAP-ENV:WSDL 中的错误

2023-12-24

我创建了 SOAP Web 服务,而且我对 SOAP 还很陌生。在创建网络服务时,我面临以下问题。

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
 <SOAP-ENV:Body>
  <SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode>
   <faultstring xml:lang="en">unexpected element (uri:"http://spring.io/guides/gs-producing-web-service", local:"getUserRequest"). Expected elements are &lt;{}getUserRequest&gt;
   </faultstring>
  </SOAP-ENV:Fault>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这是我的代码:

@Endpoint
public class UserEndpoint {
private static final String NAMESPACE_URI = "http://spring.io/guides/gs-producing-web-service";

//@SuppressWarnings("unused")
private UserRepo repo;

@Autowired
public UserEndpoint(UserRepo repo) {
    this.repo = repo;
}

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getUserRequest")
@ResponsePayload
public GetUserResponse getUser(@RequestPayload GetUserRequest request) {

    GetUserResponse response = new GetUserResponse();


     response.getUser().getContact()


     System.out.println("done!!");

    return response;
}
 }

输入 XML 文件:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:gs="http://spring.io/guides/gs-producing-web-service">
   <soapenv:Header/>
   <soapenv:Body>
      <gs:getUserRequest>
     <gs:name>Spain</gs:name>
      </gs:getUserRequest>
   </soapenv:Body>
</soapenv:Envelope>

我无法理解该错误及其原因。


要修复以下错误:

<faultstring xml:lang="en">unexpected element (uri:"http://spring.io/guides/gs-producing-web-service", local:"getCountryRequest"). Expected elements are &lt;{}getCountryRequest></faultstring>

使用 Sergey Usachev 提供的解决方案,在类 GetCountryRequest 中更改以下内容:

@XmlRootElement(namespace="http://spring.io/guides/gs-producing-web-service", name="getCountryRequest") public class GetCountryRequest {

但随后你会得到第二个错误:

<faultstring xml:lang="en">The country's name must not be null</faultstring>

要解决此问题,请在同一类中修改以下内容:

 @XmlElement(namespace="http://spring.io/guides/gs-producing-web-service", required = true)

然后,您就可以使用此地址上的 WSDL 通过 SOAP UI 测试服务:

http://localhost:8080/ws/countries.wsdl
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SOAP-ENV:WSDL 中的错误 的相关文章

随机推荐