0

我正在制作一个服务检查员来验证针对 xsd 的肥皂请求。如果请求有效负载有任何问题,我想让 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;

    }

更改服务不是一种选择,因为有很多。

4

0 回答 0