Skip to content

Instantly share code, notes, and snippets.

@woehrl01
Last active August 29, 2015 14:01
Show Gist options
  • Save woehrl01/b4cbbe934e0b2f8f3b1d to your computer and use it in GitHub Desktop.
Save woehrl01/b4cbbe934e0b2f8f3b1d to your computer and use it in GitHub Desktop.
Servicestack Exception to SoapException
/* Small snipped to transform a ServiceException into a SoapException if called from a SoapClient.
* So you don't have to check the ReturnCode value of ResponseStatus for errors.
* Feel free to use, edit, share, improve this one.
*/
using System.ServiceModel;
public override void Configure(Funq.Container funq)
{
ServiceExceptionHandlers.Add((req, request, ex) =>
{
var requestMsg = req.GetItem("SoapMessage") as System.ServiceModel.Channels.Message;
if (requestMsg != null)
{
var msgVersion = requestMsg.Version;
using (var response = XmlWriter.Create(req.Response.OutputStream))
{
var message = System.ServiceModel.Channels.Message.CreateMessage(msgVersion, new FaultCode("Receiver"), ex.ToString(), null);
message.WriteMessage(response);
}
req.Response.End();
}
return null;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment