예제 #1
0
		protected override bool OnTryCreateException (
			Message message, MessageFault fault, out Exception error)
		{
			if (message == null)
				throw new ArgumentNullException ("message");
			if (fault == null)
				throw new ArgumentNullException ("fault");

			error = null;

			FaultCode fc;
			if (version.Envelope.Equals (EnvelopeVersion.Soap11))
				fc = fault.Code;
			else
				fc = fault.Code.SubCode;

			if (fc == null)
				return false;

			string msg = fault.Reason.GetMatchingTranslation ().Text;
			if (fc.Namespace == message.Version.Addressing.Namespace) {
				switch (fc.Name) {
				case "ActionNotSupported":
					error = new ActionNotSupportedException (msg);
					return true;
				case "DestinationUnreachable":
					error = new EndpointNotFoundException (msg);
					return true;
				}
			}

			return false;
		}
 protected override bool OnTryCreateException(Message message, MessageFault fault, out Exception exception)
 {
     bool isSenderFault;
     bool isReceiverFault;
     FaultCode subCode;
     exception = null;
     if ((string.Compare(fault.Code.Namespace, this.version.Envelope.Namespace, StringComparison.Ordinal) == 0) && (string.Compare(fault.Code.Name, "MustUnderstand", StringComparison.Ordinal) == 0))
     {
         exception = new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
         return true;
     }
     if (this.version.Envelope == EnvelopeVersion.Soap11)
     {
         isSenderFault = true;
         isReceiverFault = true;
         subCode = fault.Code;
     }
     else
     {
         isSenderFault = fault.Code.IsSenderFault;
         isReceiverFault = fault.Code.IsReceiverFault;
         subCode = fault.Code.SubCode;
     }
     if (subCode != null)
     {
         if (subCode.Namespace == null)
         {
             return false;
         }
         if (isSenderFault && (string.Compare(subCode.Namespace, this.version.Addressing.Namespace, StringComparison.Ordinal) == 0))
         {
             if (string.Compare(subCode.Name, "ActionNotSupported", StringComparison.Ordinal) == 0)
             {
                 exception = new ActionNotSupportedException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                 return true;
             }
             if (string.Compare(subCode.Name, "DestinationUnreachable", StringComparison.Ordinal) == 0)
             {
                 exception = new EndpointNotFoundException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                 return true;
             }
             if (string.Compare(subCode.Name, "InvalidAddressingHeader", StringComparison.Ordinal) == 0)
             {
                 if (((subCode.SubCode != null) && (string.Compare(subCode.SubCode.Namespace, this.version.Addressing.Namespace, StringComparison.Ordinal) == 0)) && (string.Compare(subCode.SubCode.Name, "InvalidCardinality", StringComparison.Ordinal) == 0))
                 {
                     exception = new MessageHeaderException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text, true);
                     return true;
                 }
             }
             else if (this.version.Addressing == AddressingVersion.WSAddressing10)
             {
                 if (string.Compare(subCode.Name, "MessageAddressingHeaderRequired", StringComparison.Ordinal) == 0)
                 {
                     exception = new MessageHeaderException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                     return true;
                 }
                 if (string.Compare(subCode.Name, "InvalidAddressingHeader", StringComparison.Ordinal) == 0)
                 {
                     exception = new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                     return true;
                 }
             }
             else
             {
                 if (string.Compare(subCode.Name, "MessageInformationHeaderRequired", StringComparison.Ordinal) == 0)
                 {
                     exception = new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                     return true;
                 }
                 if (string.Compare(subCode.Name, "InvalidMessageInformationHeader", StringComparison.Ordinal) == 0)
                 {
                     exception = new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                     return true;
                 }
             }
         }
         if ((isReceiverFault && (string.Compare(subCode.Namespace, this.version.Addressing.Namespace, StringComparison.Ordinal) == 0)) && (string.Compare(subCode.Name, "EndpointUnavailable", StringComparison.Ordinal) == 0))
         {
             exception = new ServerTooBusyException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
             return true;
         }
     }
     return false;
 }
 private void ReadAndDispatch()
 {
     bool flag = false;
     try
     {
         while (((this.size > 0) || !this.isReadPending) && !base.IsClosed)
         {
             if (this.size == 0)
             {
                 this.isReadPending = true;
                 if (this.onAsyncReadComplete == null)
                 {
                     this.onAsyncReadComplete = new WaitCallback(this.OnAsyncReadComplete);
                 }
                 if (base.Connection.BeginRead(0, this.connectionBuffer.Length, this.GetRemainingTimeout(), this.onAsyncReadComplete, null) == AsyncReadResult.Queued)
                 {
                     break;
                 }
                 this.HandleReadComplete();
             }
             int num = this.decoder.Decode(this.connectionBuffer, this.offset, this.size);
             if (num > 0)
             {
                 this.offset += num;
                 this.size -= num;
             }
             if (this.decoder.CurrentState == ServerSingletonDecoder.State.PreUpgradeStart)
             {
                 this.via = this.decoder.Via;
                 if (!base.Connection.Validate(this.via))
                 {
                     return;
                 }
                 if (this.viaDelegate != null)
                 {
                     try
                     {
                         this.viaDelegate(this.via);
                     }
                     catch (ServiceActivationException exception)
                     {
                         if (DiagnosticUtility.ShouldTraceInformation)
                         {
                             DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
                         }
                         this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/ServiceActivationFailed");
                         break;
                     }
                 }
                 this.transportSettings = this.transportSettingsCallback(this.via);
                 if (this.transportSettings == null)
                 {
                     EndpointNotFoundException exception2 = new EndpointNotFoundException(System.ServiceModel.SR.GetString("EndpointNotFound", new object[] { this.decoder.Via }));
                     if (DiagnosticUtility.ShouldTraceInformation)
                     {
                         DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information);
                     }
                     this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/EndpointNotFound");
                     return;
                 }
                 this.callback(this);
                 break;
             }
         }
         flag = true;
     }
     catch (CommunicationException exception3)
     {
         if (DiagnosticUtility.ShouldTraceInformation)
         {
             DiagnosticUtility.ExceptionUtility.TraceHandledException(exception3, TraceEventType.Information);
         }
     }
     catch (TimeoutException exception4)
     {
         if (DiagnosticUtility.ShouldTraceInformation)
         {
             DiagnosticUtility.ExceptionUtility.TraceHandledException(exception4, TraceEventType.Information);
         }
     }
     catch (Exception exception5)
     {
         if (Fx.IsFatal(exception5))
         {
             throw;
         }
         if (!System.ServiceModel.Dispatcher.ExceptionHandler.HandleTransportExceptionHelper(exception5))
         {
             throw;
         }
     }
     finally
     {
         if (!flag)
         {
             base.Abort();
         }
     }
 }