Share via


4.3 Faults in SOAP Over HTTP

If the Remoting Method implementation of "DoIt" throws an Exception, then it is returned to the client as a SOAP fault. The HTTP headers of the reply message are shown in the following code example. The reply message is encoded as specified in Sending Reply (section 2.1.3.1.2.2) under SOAP on HTTP (section 2.1.3.1). The Status-Code is 500. The Content-Type is text/xml;charset="utf-8" which is the SOAP Format Identifier.

 Version=1.1, Status-Code=500, Reason-Phrase=Internal Server Error.Content-Length: 2312
 Content-Type: text/xml; charset="utf-8"
 Server: MS .NET Remoting, MS .NET CLR 2.0.50727.1318

The HTTP body of the reply message is given in the following sample. The body is a SOAP Envelope. The reply echoes the CallContext and MethodSignature headers. The SOAP body of the reply message contains the SOAP Fault element. It is encoded as specified in Mapping Exception (section 3.1.5.2.11). The faultcode value of SOAP-ENV:Server conveys the fault is on the server side. The faultstring contains the Exception message thrown by the application. The detail value consists of the serialized instance of the Exception. The other elements—exceptionType, message, and stackTrace—have null values. The structure of the serialized Exception message can be found in SystemException (section 2.2.2.9).

  
 <SOAP-ENV:Envelope 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
   xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
   xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" 
   SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  
   <SOAP-ENV:Header>
     <h4:__CallContext href="#ref-3" 
       xmlns:h4="http://schemas.microsoft.com/clr/soap/
 messageProperties" 
       SOAP-ENC:root="1"/>
     <a1:LogicalCallContext id="ref-3" 
       xmlns:a1="http://schemas.microsoft.com/clr/ns/System.Runtime.
 Remoting.Messaging">
       <Hdr1 id="ref-5">HeaderValue</Hdr1>
     </a1:LogicalCallContext>
   </SOAP-ENV:Header>
  
   <SOAP-ENV:Body>
     <SOAP-ENV:Fault id="ref-1">
       <faultcode id="ref-6">SOAP-ENV:Server</faultcode>
       <faultstring id="ref-7"> 
         **** System.Exception - Invalid Arguments
       </faultstring>
       <detail xsi:type="a2:ServerFault"
 xmlns:a2="http://schemas.microsoft.com/clr/ns/System.Runtime.
 Serialization.Formatters">
         <exceptionType xsi:null="1"/>
         <message xsi:null="1"/>
         <stackTrace xsi:null="1"/>
         <exception href="#ref-8"/>
       </detail>
     </SOAP-ENV:Fault>
     <a3:Exception id="ref-8" 
       xmlns:a3="http://schemas.microsoft.com/clr/ns/System">
       <ClassName id="ref-9">System.Exception</ClassName>
       <Message id="ref-10">Invalid Arguments</Message>
       <InnerException xsi:null="1"/>
       <HelpURL xsi:null="1"/>
       <StackTraceString id="ref-11">   
         at RemotingTest.MyServer.DoIt(Array a, Int32 I) in 
 C:\temp\RemotingTest\RemotingSinkTest\RemotingTest\Program.cs:line 245
         at System.Runtime.Remoting.Messaging.StackBuilderSink.
 _PrivateProcessMessage(IntPtr md, Object[] args, Object server, 
 Int32 methodPtr, Boolean fExecuteInContext, Object[] outArgs)
         at System.Runtime.Remoting.Messaging.StackBuilderSink.
 SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean 
 fExecuteInContext)
       </StackTraceString>
       <RemoteStackTraceString xsi:null="1"/>
       <RemoteStackIndex>0</RemoteStackIndex>
       <ExceptionMethod id="ref-12">8.DoIt.RemotingTest, 
 Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.RemotingTest.
 MyServer.RemotingTest.Method1 DoIt(System.Array, Int32)</ExceptionMethod>
       <HResult>-2146233079</HResult>
       <Source id="ref-13">RemotingTest</Source>
     </a3:Exception>
   </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>