| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Collections.ObjectModel; |
| | | 5 | | using System.Globalization; |
| | | 6 | | using System.Xml; |
| | | 7 | | using CoreWCF.Channels; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF |
| | | 10 | | { |
| | | 11 | | //[Serializable] |
| | | 12 | | internal class MustUnderstandSoapException : CommunicationException |
| | | 13 | | { |
| | 0 | 14 | | public MustUnderstandSoapException(Collection<MessageHeaderInfo> notUnderstoodHeaders, EnvelopeVersion envelopeV |
| | | 15 | | { |
| | 0 | 16 | | NotUnderstoodHeaders = notUnderstoodHeaders; |
| | 0 | 17 | | EnvelopeVersion = envelopeVersion; |
| | 0 | 18 | | } |
| | | 19 | | |
| | 0 | 20 | | public Collection<MessageHeaderInfo> NotUnderstoodHeaders { get; } |
| | 0 | 21 | | public EnvelopeVersion EnvelopeVersion { get; } |
| | | 22 | | |
| | | 23 | | internal Message ProvideFault(MessageVersion messageVersion) |
| | | 24 | | { |
| | 0 | 25 | | string name = NotUnderstoodHeaders[0].Name; |
| | 0 | 26 | | string ns = NotUnderstoodHeaders[0].Namespace; |
| | 0 | 27 | | FaultCode code = new FaultCode(MessageStrings.MustUnderstandFault, EnvelopeVersion.Namespace); |
| | 0 | 28 | | FaultReason reason = new FaultReason(SR.Format(SR.SFxHeaderNotUnderstood, name, ns), CultureInfo.CurrentCult |
| | 0 | 29 | | MessageFault fault = MessageFault.CreateFault(code, reason); |
| | 0 | 30 | | string faultAction = messageVersion.Addressing.DefaultFaultAction; |
| | 0 | 31 | | Message message = Channels.Message.CreateMessage(messageVersion, fault, faultAction); |
| | 0 | 32 | | if (EnvelopeVersion == EnvelopeVersion.Soap12) |
| | | 33 | | { |
| | 0 | 34 | | AddNotUnderstoodHeaders(message.Headers); |
| | | 35 | | } |
| | 0 | 36 | | return message; |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | private void AddNotUnderstoodHeaders(MessageHeaders headers) |
| | | 40 | | { |
| | 0 | 41 | | for (int i = 0; i < NotUnderstoodHeaders.Count; ++i) |
| | | 42 | | { |
| | 0 | 43 | | headers.Add(new NotUnderstoodHeader(NotUnderstoodHeaders[i].Name, NotUnderstoodHeaders[i].Namespace)); |
| | | 44 | | } |
| | 0 | 45 | | } |
| | | 46 | | |
| | | 47 | | private class NotUnderstoodHeader : MessageHeader |
| | | 48 | | { |
| | | 49 | | private readonly string _notUnderstoodName; |
| | | 50 | | private readonly string _notUnderstoodNs; |
| | | 51 | | |
| | 0 | 52 | | public NotUnderstoodHeader(string name, string ns) |
| | | 53 | | { |
| | 0 | 54 | | _notUnderstoodName = name; |
| | 0 | 55 | | _notUnderstoodNs = ns; |
| | 0 | 56 | | } |
| | | 57 | | |
| | | 58 | | public override string Name |
| | | 59 | | { |
| | 0 | 60 | | get { return Message12Strings.NotUnderstood; } |
| | | 61 | | } |
| | | 62 | | |
| | | 63 | | public override string Namespace |
| | | 64 | | { |
| | 0 | 65 | | get { return Message12Strings.Namespace; } |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | protected override void OnWriteStartHeader(XmlDictionaryWriter writer, MessageVersion messageVersion) |
| | | 69 | | { |
| | 0 | 70 | | writer.WriteStartElement(Name, Namespace); |
| | 0 | 71 | | writer.WriteXmlnsAttribute(null, _notUnderstoodNs); |
| | 0 | 72 | | writer.WriteStartAttribute(Message12Strings.QName); |
| | 0 | 73 | | writer.WriteQualifiedName(_notUnderstoodName, _notUnderstoodNs); |
| | 0 | 74 | | writer.WriteEndAttribute(); |
| | 0 | 75 | | } |
| | | 76 | | |
| | | 77 | | protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion) |
| | | 78 | | { |
| | | 79 | | // empty |
| | 0 | 80 | | } |
| | | 81 | | } |
| | | 82 | | } |
| | | 83 | | } |