Creating SOAP Error responses
I am creating a Web Service that internal client at my company will be calling. The service methods look like the following:
CreateProposalResponse ProposalSOAService::CreateProposal( CreateProposalRequest )
For the CreateProposalResponse message I need to add business Error Messages into the response. I've been reading a lot about putting errors into the SOAP Headers, but for business errors I don't feel that this is the appropriate place to put them because you this should be system/transport/validation kinds of errors not business Errors. Below is my response XML for the CreateProposal() SOA call. Can someone advice me on how to add Error messages to this response? I am having a hard time envisioning this and how the calling clients would determine the difference from a normal response and a business error/exception.
My CreateProposalResponse Message looks like the following:
<?xml version="1.0" encoding="UTF-8" ?>
<CreateProposalResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.xxx.com/aces/proposal src/Proposal_v1.0.xsd"
xmlns="http://xmlns.raytheon.com/aces/proposal">
<userId>022483</userId>
<Proposal>
<proposalTitle>SBT Prop</proposalTi开发者_高级运维tle>
<proposalDescription>Proposal is for SBT</proposalDescription>
<businessSegmentCode>SAS</businessSegmentCode>
<proposalType>Test</proposalType>
<proposalExternalRefID>SBT38829</proposalExternalRefID>
<proposalStartDate>2009-01-01</proposalStartDate>
<proposalEndDate>2025-01-01</proposalEndDate>
</Proposal>
<sourceSystemID>SBT</sourceSystemID>
<targetSystemID>ACES</targetSystemID>
</CreateProposalResponse>
I agree with Aasmund Eldhuset unless these errors are an indication that the operation has failed. In that case, you should use a SOAP Fault.
How about simply having an <errors>
array element as an optional element in your message, and populate it with one or more <error>
elements describing the error(s)? Then, you could specify that a response message will either contain a populated <errors>
element (along with other metadata elements that might be desirable even in the face of an error; perhaps <sourceSystemID>
and <targetSystemID>
are such elements?) but no <Proposal>
, or it will not contain a <Proposal>
but no <errors>
(or the element will be empty).
(By the way, I agree that business errors should be indicated in the message body, not as SOAP errors.)
精彩评论