Ejemplo n.º 1
0
		protected SecureMessageDecryptor (
			Message source, MessageSecurityBindingSupport security)
		{
			source_message = source;
			this.security = security;

			// FIXME: use proper max buffer
			buf = source.CreateBufferedCopy (int.MaxValue);
Console.WriteLine ("####### " + buf.CreateMessage ());

			doc = new XmlDocument ();
			doc.PreserveWhitespace = true;

			nsmgr = new XmlNamespaceManager (doc.NameTable);
			nsmgr.AddNamespace ("s", "http://www.w3.org/2003/05/soap-envelope");
			nsmgr.AddNamespace ("c", Constants.WsscNamespace);
			nsmgr.AddNamespace ("o", Constants.WssNamespace);
			nsmgr.AddNamespace ("e", EncryptedXml.XmlEncNamespaceUrl);
			nsmgr.AddNamespace ("u", Constants.WsuNamespace);
			nsmgr.AddNamespace ("dsig", SignedXml.XmlDsigNamespaceUrl);

		}
		Message OnGetToken (Message input)
		{
			MessageBuffer buf = input.CreateBufferedCopy (10000);
			VerifyInput2 (buf);

			// FIXME: create response message (when I understand what I should return.)
//			throw new MyException ();
//*
			XmlDocument doc = new XmlDocument ();
			doc.LoadXml ("<Response>RESPONSE</Response>");
			X509Certificate2 cert = new X509Certificate2 ("Test/Resources/test.pfx", "mono");
			SignedXml sxml = new SignedXml (doc);
			MemoryStream ms = new MemoryStream (new byte [] {1, 2, 3});
			sxml.AddReference (new Reference (ms));
			sxml.SigningKey = cert.PrivateKey;
			sxml.ComputeSignature ();

			Message msg = Message.CreateMessage (input.Version, "http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/Issue", sxml.GetXml ());
			msg.Headers.Add (MessageHeader.CreateHeader (
				"Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", null, true));

			return msg;
//*/
		}
        private Message TransformAndHandleFault(Message message)
        {
            if (message.Headers.Action.EndsWith("/fault"))
            {
                var buffer = message.CreateBufferedCopy(int.MaxValue);

                var clonedMessage = buffer.CreateMessage();

                var reader = clonedMessage.GetReaderAtBodyContents();

                reader.Read();
                reader.Read();
                reader.Read();
                reader.Read();
                reader.Read();

                var val = reader.Value;

                if (string.IsNullOrWhiteSpace(val))
                {
                    return buffer.CreateMessage();
                }
                
                if (val == Constants.SerializationFaultCode.ToString(CultureInfo.InvariantCulture))
                {
                    var store = ObjectBuilder.GetModelStore();

                    store.RemoveAll();
                }

                return buffer.CreateMessage();
            }

            return message;
        }
		Message OnGetTokenWrongResponse (Message input)
		{
			VerifyInput (input.CreateBufferedCopy (10000));

			throw new MyException ();
		}
        public void BeforeSendReply(ref Message reply, object correlationState)
        {
            if (correlationState != null)
            {
                MessageInfo messageInfo = correlationState as MessageInfo;
                if (messageInfo != null)
                {
                    messageInfo.ServerEndTimeStamp = DateTime.Now;

                    MessageBuffer mb = reply.CreateBufferedCopy(int.MaxValue);
                    Message responseMsg = mb.CreateMessage();
                    reply = mb.CreateMessage();

                    XmlDictionaryReader bodyReader = responseMsg.GetReaderAtBodyContents();
                    if (bodyReader.IsStartElement("Binary"))
                    {
                        bodyReader.ReadStartElement("Binary");
                        byte[] bodyBytes = bodyReader.ReadContentAsBase64();
                        messageInfo.Response = Encoding.UTF8.GetString(bodyBytes);
                    }
                    else
                    {
                        messageInfo.Response = bodyReader.ReadOuterXml();
                    }

                    if (reply.IsFault)
                    {
                        messageInfo.IsError = true;
                    }

                    if (messageInfo.Response.Contains("<Binary>"))
                    {

                    }

                    string message = String.Format("Response => {0} {1}", messageInfo.ServerEndTimeStamp.ToString(CultureInfo.InvariantCulture), messageInfo.Response);
                    if (IsDisplayConsole)
                    {
                        Console.WriteLine(message);
                    }

                    if (IsLogFile)
                    {
                        _logger.Log(LogLevel.Info, message);
                    }
                }

                if (OnMessage != null)
                {
                    OnMessage(this, new MessageInspectorArgs
                    {
                        MessageInspectionType = MessageInspectionType.Response,
                        Message = messageInfo
                    });
                }
            }
        }