xsd に対して入ってくる SOAP リクエストを検証するサービス インスペクタを作成しています。リクエストのペイロードに何か問題がある場合、サービスに到達する前に、AfterReceiveRequest メソッドがクライアントに適切な応答 (障害例外ではない) を返信するようにしたいと考えています。
私の AfterReceiveRequest メソッド、
en public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
MessageBuffer buffer = request.CreateBufferedCopy (int.MaxValue);
try
{
Message messageCopy = buffer.CreateMessage();
XElement payloadTovalidate = Helper.GetXmlPayload(messageCopy, _payloadStartTag);
if (payloadTovalidate != null)
{
CustomValidator validator = new CustomValidator();
validator.Validate(payloadTovalidate.ToString(), _interfaceName);
}
else
{
return new CustomException(string.Format("ERROR: Incorrect xml format in the payload or attachment. Expected object of type {0} ;", _payloadStartTag), "asd", "asdas");
}
}
catch(Exception exception)
{
throw new FaultException(exception.Message);
}
finally
{
request = buffer.CreateMessage ();
buffer.Close ();
}
return null;
}
サービスを変更することはオプションではありません。かなりの数があるからです。