Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

What is the difference between error and fault in Spring-WS SOAP calls?

I am trying to make a SOAP call through a Spring Boot application. The call is returned with statuscode 400 and a SOAP envelope with no content. When the response is processed by WebServiceTemplate, it is characterized as an error and not a fault, and it seems like the SOAP web service I’m trying to reach doesen’t recognize the request at all. The response looks like this:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header/>
  <SOAP-ENV:Body/>
</SOAP-ENV:Envelope>

I have debugged the request, and recreated it in postman / insomnia. When posting from either request tool, it seems to work fine. Even if I send trash values for the HTTP headers or the xml body, I get a response like below, along with code 400:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Body>
    <SOAP-ENV:Fault>
      <faultcode>SOAP-ENV:Client</faultcode>
      <faultstring>RequestDataInvalid Request data is invalid.</faultstring>
    </SOAP-ENV:Fault>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Even if the request contains illegal values, the webservice I’m trying to reach seems to at least recognize the request.

What is the difference between an error and a fault? A big step in solving the problem would be to know why my invalid request is considered an error and not a fault. Can it be that this might be related to connection / network issues? When looking at the SOAP web service URL, it seems like the service has some kind of relation to Microsoft Dynamics Business Central.

Base url: https://api.businesscentral.dynamics.com


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've never used WebServiceTemplate but it's possible to have something to do with the status code of the response. The SOAP specification says that a SOAP fault should be received on a status code of 500:

In case of a SOAP error while processing the request, the SOAP HTTP server MUST issue an HTTP 500 "Internal Server Error" response and include a SOAP message in the response containing a SOAP Fault element (see section 4.4) indicating the SOAP processing error.

You are getting status code 400.

A quick read of the WebServiceTemplate javadoc says this about its setCheckConnectionForFault method:

Indicates whether the connection should be checked for fault indicators (true), or whether we should rely on the message only (false). The default is true.

When using an HTTP transport, this property defines whether to check the HTTP response status code for fault indicators. Both the SOAP specification and the WS-I Basic Profile define that a Web service must return a "500 Internal Server Error" HTTP status code if the response envelope is a Fault. Setting this property to false allows this template to deal with non-conforming services.

Looks like you are dealing with a non compliant WS-I Basic Profile web service, but the WebServiceTemplate is still trying to deal with faults, even when they are not received with a 500 status code, which seems to indicate that an error that isn't a proper fault as per the SOAP and WS-I specs, is considered just that, an error.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...