shivani thakur
shivani thakur

Reputation: 229

SOAP-ENV:Fault in WSDL

I have created soap web-service,and I am really new to SOAP. While creating a web service, I'm facing the issue below.

<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>

Here is my Code:

@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;
}
 }

Input XML file:

<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>

I am not able to understand the error and its cause.

Upvotes: 5

Views: 22315

Answers (2)

drset
drset

Reputation: 151

To fix the following error:

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

use the solution provided by Sergey Usachev, in the class GetCountryRequest change the following:

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

But then you will get a second error:

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

To fix this, in the same class, modify the following:

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

Then you are ready to test the service with SOAP UI using the WSDL on this address:

http://localhost:8080/ws/countries.wsdl

Upvotes: 13

Sergey Usachev
Sergey Usachev

Reputation: 71

I think, maybe you didn't write the XML namespace in annotation @XmlRootElement for GetUserRequest class. For example:

@XmlRootElement(namespace="http://spring.io/guides/gs-producing-web-service", name="getUserRequest")

Upvotes: 7

Related Questions