shi*_*kur 2 xml soap wsdl web-services
我已经创建了肥皂网络服务,而且我对 SOAP 真的很陌生。在创建 Web 服务时,我面临以下问题。
<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 <{}getUserRequest>
</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
@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;
}
}
Run Code Online (Sandbox Code Playgroud)
输入 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>
Run Code Online (Sandbox Code Playgroud)
我无法理解错误及其原因。
小智 6
我想,也许你没有在类@XmlRootElement的注释中编写 XML 命名空间GetUserRequest。例如:
@XmlRootElement(namespace="http://spring.io/guides/gs-producing-web-service", name="getUserRequest")
Run Code Online (Sandbox Code Playgroud)
小智 6
要修复以下错误:
<faultstring xml:lang="en">unexpected element (uri:"http://spring.io/guides/gs-producing-web-service", local:"getCountryRequest"). Expected elements are <{}getCountryRequest></faultstring>
Run Code Online (Sandbox Code Playgroud)
使用 Sergey Usachev 提供的解决方案,在类 GetCountryRequest 中更改以下内容:
@XmlRootElement(namespace="http://spring.io/guides/gs-producing-web-service", name="getCountryRequest") public class GetCountryRequest {
Run Code Online (Sandbox Code Playgroud)
但是你会得到第二个错误:
<faultstring xml:lang="en">The country's name must not be null</faultstring>
Run Code Online (Sandbox Code Playgroud)
要解决此问题,请在同一类中修改以下内容:
@XmlElement(namespace="http://spring.io/guides/gs-producing-web-service", required = true)
Run Code Online (Sandbox Code Playgroud)
然后,您就可以使用此地址上的 WSDL 使用 SOAP UI 测试服务:
http://localhost:8080/ws/countries.wsdl
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7841 次 |
| 最近记录: |