我正在建立一个服务检查员来验证针对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;
}
改变服务不是一个选择,因为,有很多。