예제 #1
0
            protected override bool OnTryCreateFaultMessage(Exception exception, out Message message)
            {
                // WSA
                if (version.Addressing == AddressingVersion.WSAddressing10)
                {
                    if (exception is MessageHeaderException)
                    {
                        MessageHeaderException mhe = exception as MessageHeaderException;
                        if (mhe.HeaderNamespace == AddressingVersion.WSAddressing10.Namespace)
                        {
                            message = mhe.ProvideFault(version);
                            return(true);
                        }
                    }
                    else if (exception is ActionMismatchAddressingException)
                    {
                        ActionMismatchAddressingException amae = exception as ActionMismatchAddressingException;
                        message = amae.ProvideFault(version);
                        return(true);
                    }
                }
                if (version.Addressing != AddressingVersion.None)
                {
                    if (exception is ActionNotSupportedException)
                    {
                        ActionNotSupportedException anse = exception as ActionNotSupportedException;
                        message = anse.ProvideFault(version);
                        return(true);
                    }
                }

                // SOAP
                if (exception is MustUnderstandSoapException)
                {
                    MustUnderstandSoapException muse = exception as MustUnderstandSoapException;
                    message = muse.ProvideFault(version);
                    return(true);
                }

                message = null;
                return(false);
            }
        private Exception ProcessHttpAddressing(Message message)
        {
            Exception exception = null;

            this.AddProperties(message);
            if (message.Version.Addressing == AddressingVersion.None)
            {
                bool flag = false;
                try
                {
                    flag = message.Headers.Action == null;
                }
                catch (XmlException exception2)
                {
                    if (DiagnosticUtility.ShouldTraceInformation)
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information);
                    }
                }
                catch (CommunicationException exception3)
                {
                    if (DiagnosticUtility.ShouldTraceInformation)
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception3, TraceEventType.Information);
                    }
                }
                if (!flag)
                {
                    exception = new ProtocolException(System.ServiceModel.SR.GetString("HttpAddressingNoneHeaderOnWire", new object[] { XD.AddressingDictionary.Action.Value }));
                }
                bool flag2 = false;
                try
                {
                    flag2 = message.Headers.To == null;
                }
                catch (XmlException exception4)
                {
                    if (DiagnosticUtility.ShouldTraceInformation)
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception4, TraceEventType.Information);
                    }
                }
                catch (CommunicationException exception5)
                {
                    if (DiagnosticUtility.ShouldTraceInformation)
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception5, TraceEventType.Information);
                    }
                }
                if (!flag2)
                {
                    exception = new ProtocolException(System.ServiceModel.SR.GetString("HttpAddressingNoneHeaderOnWire", new object[] { XD.AddressingDictionary.To.Value }));
                }
                message.Headers.To = message.Properties.Via;
            }
            if (this.isRequest)
            {
                string soapActionHeader = null;
                if (message.Version.Envelope == EnvelopeVersion.Soap11)
                {
                    soapActionHeader = this.SoapActionHeader;
                }
                else if ((message.Version.Envelope == EnvelopeVersion.Soap12) && !string.IsNullOrEmpty(this.ContentType))
                {
                    System.Net.Mime.ContentType type = new System.Net.Mime.ContentType(this.ContentType);
                    if ((type.MediaType == "multipart/related") && type.Parameters.ContainsKey("start-info"))
                    {
                        soapActionHeader = new System.Net.Mime.ContentType(type.Parameters["start-info"]).Parameters["action"];
                    }
                    if (soapActionHeader == null)
                    {
                        soapActionHeader = type.Parameters["action"];
                    }
                }
                if (soapActionHeader != null)
                {
                    soapActionHeader = UrlUtility.UrlDecode(soapActionHeader, Encoding.UTF8);
                    if (((soapActionHeader.Length >= 2) && (soapActionHeader[0] == '"')) && (soapActionHeader[soapActionHeader.Length - 1] == '"'))
                    {
                        soapActionHeader = soapActionHeader.Substring(1, soapActionHeader.Length - 2);
                    }
                    if (message.Version.Addressing == AddressingVersion.None)
                    {
                        message.Headers.Action = soapActionHeader;
                    }
                    try
                    {
                        if ((soapActionHeader.Length > 0) && (string.Compare(message.Headers.Action, soapActionHeader, StringComparison.Ordinal) != 0))
                        {
                            exception = new ActionMismatchAddressingException(System.ServiceModel.SR.GetString("HttpSoapActionMismatchFault", new object[] { message.Headers.Action, soapActionHeader }), message.Headers.Action, soapActionHeader);
                        }
                    }
                    catch (XmlException exception6)
                    {
                        if (DiagnosticUtility.ShouldTraceInformation)
                        {
                            DiagnosticUtility.ExceptionUtility.TraceHandledException(exception6, TraceEventType.Information);
                        }
                    }
                    catch (CommunicationException exception7)
                    {
                        if (DiagnosticUtility.ShouldTraceInformation)
                        {
                            DiagnosticUtility.ExceptionUtility.TraceHandledException(exception7, TraceEventType.Information);
                        }
                    }
                }
            }
            this.ApplyChannelBinding(message);
            if (DiagnosticUtility.ShouldUseActivity)
            {
                TraceUtility.TransferFromTransport(message);
            }
            if (DiagnosticUtility.ShouldTraceInformation)
            {
                TraceUtility.TraceEvent(TraceEventType.Information, 0x40013, System.ServiceModel.SR.GetString("TraceCodeMessageReceived"), MessageTransmitTraceRecord.CreateReceiveTraceRecord(message), this, null, message);
            }
            if (MessageLogger.LoggingEnabled && (message.Version.Addressing == AddressingVersion.None))
            {
                MessageLogger.LogMessage(ref message, MessageLoggingSource.LastChance | MessageLoggingSource.TransportReceive);
            }
            return(exception);
        }
예제 #3
0
        // makes sure that appropriate HTTP level headers are included in the received Message
        private Exception ProcessHttpAddressing(Message message)
        {
            Exception result = null;
            AddProperties(message);

            // check if user is receiving WS-1 messages
            if (message.Version.Addressing == AddressingVersion.None)
            {
                bool actionAbsent = false;
                try
                {
                    actionAbsent = (message.Headers.Action == null);
                }
                catch (XmlException)
                {
                }
                catch (CommunicationException)
                {
                }
                if (!actionAbsent)
                {
                    result = new ProtocolException(SR.Format(SR.HttpAddressingNoneHeaderOnWire,
                        XD.AddressingDictionary.Action.Value));
                }

                bool toAbsent = false;
                try
                {
                    toAbsent = (message.Headers.To == null);
                }
                catch (XmlException)
                {
                }
                catch (CommunicationException)
                {
                }

                if (!toAbsent)
                {
                    result = new ProtocolException(SR.Format(SR.HttpAddressingNoneHeaderOnWire,
                        XD.AddressingDictionary.To.Value));
                }
                message.Headers.To = message.Properties.Via;
            }

            if (_isRequest)
            {
                string action = null;

                if (message.Version.Envelope == EnvelopeVersion.Soap11)
                {
                    action = SoapActionHeader;
                }
                else if (message.Version.Envelope == EnvelopeVersion.Soap12 && !String.IsNullOrEmpty(ContentType))
                {
                    MediaTypeHeaderValue parsedContentType = MediaTypeHeaderValue.Parse(ContentType);
                    foreach (NameValueHeaderValue actionParam in parsedContentType.Parameters)
                    {
                        if (actionParam.Name == "action")
                        {
                            action = actionParam.Value;
                            break;
                        }
                    }
                }

                if (action != null)
                {
                    action = UrlUtility.UrlDecode(action, Encoding.UTF8);

                    if (action.Length >= 2 && action[0] == '"' && action[action.Length - 1] == '"')
                    {
                        action = action.Substring(1, action.Length - 2);
                    }

                    if (message.Version.Addressing == AddressingVersion.None)
                    {
                        message.Headers.Action = action;
                    }

                    try
                    {
                        if (action.Length > 0 && string.Compare(message.Headers.Action, action, StringComparison.Ordinal) != 0)
                        {
                            result = new ActionMismatchAddressingException(SR.Format(SR.HttpSoapActionMismatchFault,
                                message.Headers.Action, action), message.Headers.Action, action);
                        }
                    }
                    catch (XmlException)
                    {
                    }
                    catch (CommunicationException)
                    {
                    }
                }
            }

            return result;
        }