Last active
August 29, 2015 14:01
-
-
Save woehrl01/b4cbbe934e0b2f8f3b1d to your computer and use it in GitHub Desktop.
Servicestack Exception to SoapException
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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