Beispiel #1
0
    public static void UnknownUrl_Throws_EndpointNotFoundException()
    {
        // We need a running service host at the other end but mangle the endpoint suffix
        string                       notFoundUrl     = Endpoints.HttpBaseAddress_Basic + "not-an-endpoint";
        BasicHttpBinding             binding         = null;
        ChannelFactory <IWcfService> factory         = null;
        EndpointAddress              endpointAddress = null;
        IWcfService                  serviceProxy    = null;

        // *** VALIDATE *** \\
        EndpointNotFoundException exception = Assert.Throws <EndpointNotFoundException>(() =>
        {
            // *** SETUP *** \\
            binding             = new BasicHttpBinding();
            binding.SendTimeout = TimeSpan.FromMilliseconds(10000);
            endpointAddress     = new EndpointAddress(notFoundUrl);
            factory             = new ChannelFactory <IWcfService>(binding, endpointAddress);
            serviceProxy        = factory.CreateChannel();

            // *** EXECUTE *** \\
            try
            {
                serviceProxy.Echo("Hello");
            }
            finally
            {
                // *** ENSURE CLEANUP *** \\
                ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
            }
        });

        // *** ADDITIONAL VALIDATION FOR NET NATIVE *** \\
        // On .Net Native retail, exception message is stripped to include only parameter
        Assert.True(exception.Message.Contains(notFoundUrl), string.Format("Expected exception message to contain: '{0}'\nThe exception message was:{1}", notFoundUrl, exception.Message));
    }
        private void EndpointNotFoundExceptionHandler(IInvocation invocation, EndpointNotFoundException exception)
        {
            var methodName = invocation.Method.Name;
            var message    = $"{exception.Message} error in method {methodName}.";

            this._loggerService.LogMessage(message, LogLevel.Error);

            this._loggerService.LogMessage(
                new LogMessage
            {
                ClassName  = this.ToString(),
                Message    = exception.Message,
                MethodName = invocation.Method.Name
            },
                LogLevel.Debug);

            throw new System.ServiceModel.FaultException <ExceptionDetail>(
                      new ExceptionDetail(
                          false,
                          $"{exception.Message} error in method {methodName}.",
                          methodName,
                          status: ErrorCode.ConnectionError,
                          exceptionType: exception.GetType()),
                      message
                      );
        }
        public void EndpointNotFoundExceptionConstructorTest4()
        {
            string errorMessage = "This is an error message.";
            EndpointNotFoundException target = new EndpointNotFoundException(errorMessage);

            Assert.AreEqual(target.Message, errorMessage);
        }
Beispiel #4
0
    public static void NotExistentHost_Throws_EndpointNotFoundException()
    {
        string nonExistentHost = "http://nonexisthost/WcfService/WindowsCommunicationFoundation";
        ChannelFactory <IWcfService> factory = null;
        EndpointAddress  endpointAddress     = null;
        BasicHttpBinding binding             = null;
        IWcfService      serviceProxy        = null;


        // *** VALIDATE *** \\
        EndpointNotFoundException exception = Assert.Throws <EndpointNotFoundException>(() =>
        {
            // *** SETUP *** \\
            binding             = new BasicHttpBinding();
            binding.SendTimeout = TimeSpan.FromMilliseconds(40000);
            endpointAddress     = new EndpointAddress(nonExistentHost);
            factory             = new ChannelFactory <IWcfService>(binding, endpointAddress);
            serviceProxy        = factory.CreateChannel();

            // *** EXECUTE *** \\
            try
            {
                serviceProxy.Echo("Hello");
            }
            finally
            {
                // *** ENSURE CLEANUP *** \\
                ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
            }
        });

        // *** ADDITIONAL VALIDATION FOR NET NATIVE *** \\
        // On .Net Native retail, exception message is stripped to include only parameter
        Assert.True(exception.Message.Contains(nonExistentHost), string.Format("Expected exception message to contain: '{0}'\nThe exception message was: {1}", nonExistentHost, exception.Message));
    }
Beispiel #5
0
        public static Exception Unwrap(CommunicationException exception)
        {
            if (exception == null)
            {
                return(null);
            }
            FaultException faultException = exception as FaultException;

            if (faultException != null)
            {
                return(MessagingExceptionHelper.Unwrap(faultException));
            }
            EndpointNotFoundException endpointNotFoundException = exception as EndpointNotFoundException;

            if (endpointNotFoundException != null)
            {
                return(new MessagingCommunicationException(endpointNotFoundException.Message, endpointNotFoundException));
            }
            if (exception is CommunicationObjectAbortedException)
            {
                return(new OperationCanceledException(SRClient.EntityClosedOrAborted, exception));
            }
            if (exception is CommunicationObjectFaultedException)
            {
                return(new MessagingCommunicationException(SRClient.MessagingCommunicationError, exception));
            }
            return(new MessagingCommunicationException(exception.Message, exception));
        }
        public void EndpointNotFoundExceptionConstructorTest3()
        {
            string message = "Ids service endpoint was not found.";
            EndpointNotFoundException target = new EndpointNotFoundException();

            Assert.AreEqual(target.Message, message);
        }
Beispiel #7
0
        public void EndpointNotFoundException()
        {
            var before = new EndpointNotFoundException("Hello");

            Assert.AreEqual(ErrorCode.EndpointNotFound, before.ErrorCode);
            Assert.AreEqual("Hello", before.Message);
        }
Beispiel #8
0
        //returns false if the connection should be aborted
        bool ContinuePostValidationProcessing()
        {
            if (viaDelegate != null)
            {
                try
                {
                    viaDelegate(via);
                }
                catch (ServiceActivationException e)
                {
                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                    // return fault and close connection
                    SendFault(FramingEncodingString.ServiceActivationFailedFault);
                    return(true);
                }
            }


            transportSettings = transportSettingsCallback(via);

            if (transportSettings == null)
            {
                EndpointNotFoundException e = new EndpointNotFoundException(SR.Format(SR.EndpointNotFound, decoder.Via));
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                // return fault and close connection
                SendFault(FramingEncodingString.EndpointNotFoundFault);
                return(false);
            }

            // we have enough information to hand off to a channel. Our job is done
            callback(this);
            return(true);
        }
Beispiel #9
0
 void Report(EndpointNotFoundException exception)
 {
     Report((Exception)exception);
     Console.Error.WriteLine();
     Console.Error.WriteLine(
         ProgramInfo.ProgramName + ": Open the file " +
         ProgramInfo.ProgramName + ".config and configure the SOAP service endpoint.");
 }
Beispiel #10
0
        public void SetRoleInstanceCountProcess()
        {
            Func <XElement, bool> func = null;

            this.GetCurrentDeployment();
            if (this.currentDeployment != null)
            {
                using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
                {
                    try
                    {
                        XNamespace             xNamespace = "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration";
                        XDocument              xDocument  = XDocument.Parse(ServiceManagementHelper.DecodeFromBase64String(this.currentDeployment.Configuration));
                        IEnumerable <XElement> xElements  = xDocument.Root.Elements(xNamespace + "Role");
                        if (func == null)
                        {
                            func = (XElement p) => string.Compare(p.Attribute("name").Value, this.RoleName, true) == 0;
                        }
                        XElement xElement = xElements.Where <XElement>(func).SingleOrDefault <XElement>();
                        if (xElement != null)
                        {
                            xElement.Element(xNamespace + "Instances").SetAttributeValue("count", this.Count);
                        }
                        using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
                        {
                            ChangeConfigurationInput changeConfigurationInput = new ChangeConfigurationInput();
                            changeConfigurationInput.Configuration = ServiceManagementHelper.EncodeToBase64String(xDocument.ToString());
                            ChangeConfigurationInput changeConfigurationInput1 = changeConfigurationInput;
                            CmdletExtensions.WriteVerboseOutputForObject(this, xDocument);
                            base.RetryCall((string s) => base.Channel.ChangeConfigurationBySlot(s, this.ServiceName, this.Slot, changeConfigurationInput1));
                            Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                            ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                            managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                            managementOperationContext.set_OperationId(operation.OperationTrackingId);
                            managementOperationContext.set_OperationStatus(operation.Status);
                            ManagementOperationContext managementOperationContext1 = managementOperationContext;
                            base.WriteObject(managementOperationContext1, true);
                        }
                    }
                    catch (EndpointNotFoundException endpointNotFoundException1)
                    {
                        EndpointNotFoundException endpointNotFoundException = endpointNotFoundException1;
                        this.WriteErrorDetails(endpointNotFoundException);
                    }
                    catch (CommunicationException communicationException1)
                    {
                        CommunicationException communicationException = communicationException1;
                        this.WriteErrorDetails(communicationException);
                    }
                }
                return;
            }
            else
            {
                return;
            }
        }
        public void EndpointNotFoundExceptionConstructorTest5()
        {
            string errorMessage = "This is an error message.";

            System.Exception          innerException = new ArgumentNullException();
            EndpointNotFoundException target         = new EndpointNotFoundException(errorMessage, innerException);

            Assert.AreEqual(target.Message, errorMessage);
            Assert.ReferenceEquals(target.InnerException, innerException);
        }
        public void OMM_Exception_Simple_MappedToResourcese_NoSubConfiguration()
        {
            EndpointNotFoundException ex = new EndpointNotFoundException();
            string value1 = ObjectMessageMap.GetMessage(ex);
            string value2 = ObjectMessageMap.GetMessage(typeof(EndpointNotFoundException));

            Assert.AreEqual(value1, value2);

            Assert.AreEqual(TestResources.SERVER_NOT_FOUND, value1);
        }
Beispiel #13
0
        static string ConvertWebError(Exception ex0,
                                      string strUrl)
        {
            if (ex0 is EndpointNotFoundException)
            {
                EndpointNotFoundException ex = (EndpointNotFoundException)ex0;
                return("服务器 " + strUrl + " 没有响应");
            }

            return(GetExceptionMessage(ex0));
        }
        public void EndpointNotFoundExceptionConstructorTest()
        {
            string errorMessage = "Unauthorized";
            string errorCode    = "401";
            string source       = "Intuit.Ipp.Test";
            EndpointNotFoundException target = new EndpointNotFoundException(errorMessage, errorCode, source);

            Assert.AreEqual(target.Message, errorMessage);
            Assert.AreEqual(target.ErrorCode, errorCode);
            Assert.AreEqual(target.Source, source);
        }
Beispiel #15
0
 void SendEndpointNotFound(RequestContext rc, EndpointNotFoundException ex)
 {
     try {
         MessageVersion version = rc.RequestMessage.Version;
         FaultCode      fc      = new FaultCode("DestinationUnreachable", version.Addressing.Namespace);
         Message        res     = Message.CreateMessage(version, fc, "error occured", rc.RequestMessage.Headers.Action);
         rc.Reply(res);
     } catch (Exception e) {
         // FIXME: log it
         Console.WriteLine("Error on sending DestinationUnreachable fault message: " + e);
     }
 }
Beispiel #16
0
        /// <summary>
        /// Indicates whether the specified <see cref="Exception"/> is
        /// related to an endpoint not being available.
        /// </summary>
        /// <param name="exception"></param>
        /// <returns></returns>
        public static bool IsEndpointDown(System.Exception exception)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }

            EndpointNotFoundException endpointNotFoundException = exception as EndpointNotFoundException;

            if (endpointNotFoundException != null)
            {
                return(true);
            }

            ServerTooBusyException serverTooBusyException = exception as ServerTooBusyException;

            if (serverTooBusyException != null)
            {
                WebException webException = serverTooBusyException.InnerException as WebException;
                return(IsEndpointDown(webException));
            }

            TimeoutException timeoutException = exception as TimeoutException;

            if (timeoutException != null)
            {
                return(true);
            }

            DataServiceTransportException dataServiceTransportException = exception as DataServiceTransportException;

            if (dataServiceTransportException != null)
            {
                WebException webException = dataServiceTransportException.InnerException as WebException;
                return(IsEndpointDown(webException));
            }

            DataServiceRequestException dataServiceRequestException = exception as DataServiceRequestException;

            if (dataServiceRequestException != null)
            {
                DataServiceClientException dataServiceClientException =
                    dataServiceRequestException.InnerException as DataServiceClientException;
                if (dataServiceClientException != null)
                {
                    WebException webException = dataServiceClientException.InnerException as WebException;
                    return(IsEndpointDown(webException));
                }
            }

            return(false);
        }
        public void EndpointNotFoundExceptionConstructorTest1()
        {
            string errorMessage = "Unauthorized";
            string errorCode    = "401";
            string source       = "Intuit.Ipp.Test";

            System.Exception          innerException = new ArgumentNullException();
            EndpointNotFoundException target         = new EndpointNotFoundException(errorMessage, errorCode, source, innerException);

            Assert.AreEqual(target.Message, errorMessage);
            Assert.AreEqual(target.ErrorCode, errorCode);
            Assert.AreEqual(target.Source, source);
            Assert.ReferenceEquals(target.InnerException, innerException);
        }
    public static void UnknownUrl_Throws_EndpointNotFoundException()
    {
        // We need a running service host at the other end but mangle the endpoint suffix
        string notFoundUrl = Endpoints.HttpBaseAddress_Basic + "not-an-endpoint";

        BasicHttpBinding binding = new BasicHttpBinding();

        binding.SendTimeout = TimeSpan.FromMilliseconds(10000);

        EndpointNotFoundException exception = Assert.Throws <EndpointNotFoundException>(() =>
        {
            try
            {
                using (
                    ChannelFactory <IWcfService> factory = new ChannelFactory <IWcfService>(binding,
                                                                                            new EndpointAddress(notFoundUrl)))
                {
                    IWcfService serviceProxy = factory.CreateChannel();
                    string response          = serviceProxy.Echo("Hello");
                }
            }
            catch (EndpointNotFoundException)
            {
                throw;
            }
            catch (CommunicationException ce)
            {
                if (ce.InnerException == null)
                {
                    throw;
                }

                if (ce.InnerException.GetType() == typeof(HttpRequestException))
                {
                    var httpReqExcep = ce.InnerException as HttpRequestException;
                    StringBuilder sb = new StringBuilder();
                    sb.Append("Received HttpRequestException with unknown error code ")
                    .AppendLine(ce.InnerException.HResult.ToString())
                    .AppendLine("Full details for HttpRequestException:")
                    .AppendLine(httpReqExcep.ToString());
                    throw new CommunicationException(sb.ToString());
                }

                throw;
            }
        });

        // On .Net Native retail, exception message is stripped to include only parameter
        Assert.True(exception.Message.Contains(notFoundUrl), string.Format("Expected exception message to contain: '{0}'", notFoundUrl));
    }
Beispiel #19
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);
        }
        /// <summary>
        /// Exceptions thrown during broker proxy and service host communication
        /// are wrapped into FaultException(ProxyFault) and passed back to
        /// AzureDispatcher. Here we check if the message is a fault message that
        /// carries ProxyFault. If so, extract the inner exception from ProxyFault
        /// and throw it out. Dispatcher will handle the exception as if it is
        /// talking to service host directly.
        /// </summary>
        /// <param name="message">response message</param>
        protected override void PostProcessMessage(Message message)
        {
            if (message.IsFault)
            {
                if (message.Headers.Action == ProxyFault.Action)
                {
                    MessageFault fault = MessageFault.CreateFault(message, int.MaxValue);

                    ProxyFault proxyFault = fault.GetDetail <ProxyFault>();

                    if (proxyFault != null)
                    {
                        // Create exception according to the FaultCode, and mark it as "indirect"
                        // by setting its source to IndirectExceptionMark. This mark will later
                        // be checked by dispatcher to determine if it need to recreate the
                        // underlying WCF channel. For indirect exception, we don't need to
                        // recreate the channel(between dispatcher and broker proxy).
                        Exception e;

                        if (proxyFault.FaultCode == ProxyFault.ProxyEndpointNotFound)
                        {
                            // will throw EndpointNotFoundException for ProxyFault.ProxyEndpointNotFound
                            e = new EndpointNotFoundException(proxyFault.Message);
                        }
                        else if (proxyFault.FaultCode == ProxyFault.ProxyCommunicationException)
                        {
                            // will throw CommunicationException for ProxyFault.ProxyCommunicationException
                            e = new CommunicationException(proxyFault.Message);
                        }
                        else
                        {
                            // will throw general exception for other FaultCode
                            e = new Exception(proxyFault.Message);
                        }

                        e.Source = IndirectExceptionMark;

                        throw e;
                    }
                }
            }
        }
    public static void NotExistentHost_Throws_EndpointNotFoundException()
    {
        string nonExistentHost = "http://nonexisthost/WcfService/WindowsCommunicationFoundation";

        BasicHttpBinding binding = new BasicHttpBinding();

        binding.SendTimeout = TimeSpan.FromMilliseconds(10000);

        EndpointNotFoundException exception = Assert.Throws <EndpointNotFoundException>(() =>
        {
            using (ChannelFactory <IWcfService> factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(nonExistentHost)))
            {
                IWcfService serviceProxy = factory.CreateChannel();
                string response          = serviceProxy.Echo("Hello");
            }
        });

        // On .Net Native retail, exception message is stripped to include only parameter
        Assert.True(exception.Message.Contains(nonExistentHost), string.Format("Expected exception message to contain: '{0}'", nonExistentHost));
    }
Beispiel #22
0
        public static CommunicationException ConvertToCommunicationException(MessagingException exception, out bool shouldFault)
        {
            shouldFault = false;
            if (exception is MessagingEntityNotFoundException)
            {
                shouldFault = true;
                return(new EndpointNotFoundException(exception.Message, exception));
            }
            if (exception is MessagingCommunicationException)
            {
                EndpointNotFoundException innerException = exception.InnerException as EndpointNotFoundException;
                if (innerException != null)
                {
                    shouldFault = true;
                    return(innerException);
                }
            }
            CommunicationException communicationException = exception.InnerException as CommunicationException ?? new CommunicationException(exception.Message, exception);

            return(communicationException);
        }
        public static Exception ToCommunicationContract(Exception exception)
        {
            Exception     communicationContract = null;
            AmqpException amqpException         = exception as AmqpException;
            AmqpException amqpException1        = amqpException;

            if (amqpException != null)
            {
                communicationContract = ExceptionHelper.ToCommunicationContract(amqpException1.Error, amqpException1);
            }
            else if (exception is CommunicationException || exception is TimeoutException)
            {
                communicationContract = exception;
            }
            else
            {
                SocketException socketException  = exception as SocketException;
                SocketException socketException1 = socketException;
                if (socketException != null)
                {
                    if (socketException1.SocketErrorCode == SocketError.ConnectionRefused || socketException1.SocketErrorCode == SocketError.HostDown || socketException1.SocketErrorCode == SocketError.HostNotFound || socketException1.SocketErrorCode == SocketError.HostUnreachable)
                    {
                        communicationContract = new EndpointNotFoundException(socketException1.Message, socketException1);
                    }
                    else if (socketException1.SocketErrorCode == SocketError.TimedOut)
                    {
                        communicationContract = new TimeoutException(socketException1.Message, socketException1);
                    }
                }
            }
            if (communicationContract == null)
            {
                communicationContract = new CommunicationException(exception.Message, exception);
            }
            return(communicationContract);
        }
        public void EndpointNotFoundExceptionConstructorTest2()
        {
            string errorMessage = "Unauthorized";
            string errorCode    = "401";
            string source       = "Intuit.Ipp.Test";

            System.Exception          innerException = new ArgumentNullException();
            EndpointNotFoundException target         = new EndpointNotFoundException(errorMessage, errorCode, source, innerException);
            EndpointNotFoundException newTarget      = null;

            using (Stream s = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(s, target);
                s.Position = 0; // Reset stream position
                newTarget  = (EndpointNotFoundException)formatter.Deserialize(s);
            }

            Assert.IsNotNull(newTarget);
            Assert.AreEqual(newTarget.Message, errorMessage);
            Assert.AreEqual(newTarget.ErrorCode, errorCode);
            Assert.AreEqual(newTarget.Source, source);
            Assert.ReferenceEquals(newTarget.InnerException, innerException);
        }
Beispiel #25
0
            protected override bool OnTryCreateException(Message message, MessageFault fault, out Exception exception)
            {
                exception = null;

                // SOAP MustUnderstand
                if (string.Compare(fault.Code.Namespace, version.Envelope.Namespace, StringComparison.Ordinal) == 0 &&
                    string.Compare(fault.Code.Name, MessageStrings.MustUnderstandFault, StringComparison.Ordinal) == 0)
                {
                    exception = new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                    return(true);
                }

                bool      checkSender;
                bool      checkReceiver;
                FaultCode code;

                if (version.Envelope == EnvelopeVersion.Soap11)
                {
                    checkSender   = true;
                    checkReceiver = true;
                    code          = fault.Code;
                }
                else
                {
                    checkSender   = fault.Code.IsSenderFault;
                    checkReceiver = fault.Code.IsReceiverFault;
                    code          = fault.Code.SubCode;
                }

                if (code == null)
                {
                    return(false);
                }

                if (code.Namespace == null)
                {
                    return(false);
                }

                if (checkSender)
                {
                    // WS-Addressing
                    if (string.Compare(code.Namespace, version.Addressing.Namespace, StringComparison.Ordinal) == 0)
                    {
                        if (string.Compare(code.Name, AddressingStrings.ActionNotSupported, StringComparison.Ordinal) == 0)
                        {
                            exception = new ActionNotSupportedException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                            return(true);
                        }
                        else if (string.Compare(code.Name, AddressingStrings.DestinationUnreachable, StringComparison.Ordinal) == 0)
                        {
                            exception = new EndpointNotFoundException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                            return(true);
                        }
                        else if (string.Compare(code.Name, Addressing10Strings.InvalidAddressingHeader, StringComparison.Ordinal) == 0)
                        {
                            if (code.SubCode != null && string.Compare(code.SubCode.Namespace, version.Addressing.Namespace, StringComparison.Ordinal) == 0 &&
                                string.Compare(code.SubCode.Name, Addressing10Strings.InvalidCardinality, StringComparison.Ordinal) == 0)
                            {
                                exception = new MessageHeaderException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text, true);
                                return(true);
                            }
                        }
                        else if (version.Addressing == AddressingVersion.WSAddressing10)
                        {
                            if (string.Compare(code.Name, Addressing10Strings.MessageAddressingHeaderRequired, StringComparison.Ordinal) == 0)
                            {
                                exception = new MessageHeaderException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                                return(true);
                            }
                            else if (string.Compare(code.Name, Addressing10Strings.InvalidAddressingHeader, StringComparison.Ordinal) == 0)
                            {
                                exception = new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                                return(true);
                            }
                        }
                        else
                        {
                            if (string.Compare(code.Name, Addressing200408Strings.MessageInformationHeaderRequired, StringComparison.Ordinal) == 0)
                            {
                                exception = new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                                return(true);
                            }
                            else if (string.Compare(code.Name, Addressing200408Strings.InvalidMessageInformationHeader, StringComparison.Ordinal) == 0)
                            {
                                exception = new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                                return(true);
                            }
                        }
                    }
                }

                if (checkReceiver)
                {
                    // WS-Addressing
                    if (string.Compare(code.Namespace, version.Addressing.Namespace, StringComparison.Ordinal) == 0)
                    {
                        if (string.Compare(code.Name, AddressingStrings.EndpointUnavailable, StringComparison.Ordinal) == 0)
                        {
                            exception = new ServerTooBusyException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                            return(true);
                        }
                    }
                }

                return(false);
            }
Beispiel #26
0
 public void UnknownEndpoint(EndpointNotFoundException ex)
 {
 }
        private void ContinueReading()
        {
            bool flag = false;

            try
            {
                try
                {
                    while (true)
                    {
                        if (this.size == 0)
                        {
                            if (Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.readCallback == null)
                            {
                                Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.readCallback = new WaitCallback(Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.ReadCallback);
                            }
                            if (base.Connection.BeginRead(0, (int)this.connectionBuffer.Length, this.GetRemainingTimeout(), Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.readCallback, this) == AsyncReadResult.Queued)
                            {
                                break;
                            }
                            this.GetReadResult();
                        }
                        int num = this.decoder.Decode(this.connectionBuffer, this.offset, this.size);
                        if (num > 0)
                        {
                            Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader serverSessionPreambleConnectionReader = this;
                            serverSessionPreambleConnectionReader.offset = serverSessionPreambleConnectionReader.offset + num;
                            Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader serverSessionPreambleConnectionReader1 = this;
                            serverSessionPreambleConnectionReader1.size = serverSessionPreambleConnectionReader1.size - num;
                        }
                        if (this.decoder.CurrentState == Microsoft.ServiceBus.Channels.ServerSessionDecoder.State.PreUpgradeStart)
                        {
                            this.via = this.decoder.Via;
                            if (base.Connection.Validate(this.via))
                            {
                                if (this.viaDelegate != null)
                                {
                                    try
                                    {
                                        this.viaDelegate(this.via);
                                    }
                                    catch (ServiceActivationException serviceActivationException1)
                                    {
                                        ServiceActivationException serviceActivationException = serviceActivationException1;
                                        if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation)
                                        {
                                            Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.TraceHandledException(serviceActivationException, TraceEventType.Information);
                                        }
                                        this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/ServiceActivationFailed");
                                        break;
                                    }
                                }
                                this.settings = this.transportSettingsCallback(this.via);
                                if (this.settings != null)
                                {
                                    this.callback(this);
                                    break;
                                }
                                else
                                {
                                    string   endpointNotFound = Resources.EndpointNotFound;
                                    object[] via = new object[] { this.decoder.Via };
                                    EndpointNotFoundException endpointNotFoundException = new EndpointNotFoundException(Microsoft.ServiceBus.SR.GetString(endpointNotFound, via));
                                    if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation)
                                    {
                                        Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.TraceHandledException(endpointNotFoundException, TraceEventType.Information);
                                    }
                                    this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/EndpointNotFound");
                                    return;
                                }
                            }
                            else
                            {
                                return;
                            }
                        }
                    }
                    flag = true;
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation)
                    {
                        Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.TraceHandledException(communicationException, TraceEventType.Information);
                    }
                }
                catch (TimeoutException timeoutException1)
                {
                    TimeoutException timeoutException = timeoutException1;
                    if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation)
                    {
                        Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.TraceHandledException(timeoutException, TraceEventType.Information);
                    }
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    if (!ExceptionHandler.HandleTransportExceptionHelper(exception))
                    {
                        throw;
                    }
                }
            }
            finally
            {
                if (!flag)
                {
                    base.Abort();
                }
            }
        }
Beispiel #28
0
 public virtual void EndpointNotFoundException(EndpointNotFoundException ex, Types.ErrorLevel typeErrorLevel)
 {
     Logginglog4Net(ex, typeErrorLevel);
     //PrintException(ex, printResult);
     return;
 }
            protected override bool OnTryCreateException(Message message, MessageFault fault, out Exception exception)
            {
                exception = null;

                // SOAP MustUnderstand
                if (string.Compare(fault.Code.Namespace, _version.Envelope.Namespace, StringComparison.Ordinal) == 0
                    && string.Compare(fault.Code.Name, MessageStrings.MustUnderstandFault, StringComparison.Ordinal) == 0)
                {
                    exception = new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                    return true;
                }

                bool checkSender;
                bool checkReceiver;
                FaultCode code;

                if (_version.Envelope == EnvelopeVersion.Soap11)
                {
                    checkSender = true;
                    checkReceiver = true;
                    code = fault.Code;
                }
                else
                {
                    checkSender = fault.Code.IsSenderFault;
                    checkReceiver = fault.Code.IsReceiverFault;
                    code = fault.Code.SubCode;
                }

                if (code == null)
                {
                    return false;
                }

                if (code.Namespace == null)
                {
                    return false;
                }

                if (checkSender)
                {
                    // WS-Addressing
                    if (string.Compare(code.Namespace, _version.Addressing.Namespace, StringComparison.Ordinal) == 0)
                    {
                        if (string.Compare(code.Name, AddressingStrings.ActionNotSupported, StringComparison.Ordinal) == 0)
                        {
                            exception = new ActionNotSupportedException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                            return true;
                        }
                        else if (string.Compare(code.Name, AddressingStrings.DestinationUnreachable, StringComparison.Ordinal) == 0)
                        {
                            exception = new EndpointNotFoundException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                            return true;
                        }
                        else if (string.Compare(code.Name, Addressing10Strings.InvalidAddressingHeader, StringComparison.Ordinal) == 0)
                        {
                            if (code.SubCode != null && string.Compare(code.SubCode.Namespace, _version.Addressing.Namespace, StringComparison.Ordinal) == 0 &&
                                string.Compare(code.SubCode.Name, Addressing10Strings.InvalidCardinality, StringComparison.Ordinal) == 0)
                            {
                                exception = new MessageHeaderException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text, true);
                                return true;
                            }
                        }
                        else if (_version.Addressing == AddressingVersion.WSAddressing10)
                        {
                            if (string.Compare(code.Name, Addressing10Strings.MessageAddressingHeaderRequired, StringComparison.Ordinal) == 0)
                            {
                                exception = new MessageHeaderException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                                return true;
                            }
                            else if (string.Compare(code.Name, Addressing10Strings.InvalidAddressingHeader, StringComparison.Ordinal) == 0)
                            {
                                exception = new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                                return true;
                            }
                        }
                        else
                        {
                            if (string.Compare(code.Name, Addressing200408Strings.MessageInformationHeaderRequired, StringComparison.Ordinal) == 0)
                            {
                                exception = new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                                return true;
                            }
                            else if (string.Compare(code.Name, Addressing200408Strings.InvalidMessageInformationHeader, StringComparison.Ordinal) == 0)
                            {
                                exception = new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                                return true;
                            }
                        }
                    }
                }

                if (checkReceiver)
                {
                    // WS-Addressing
                    if (string.Compare(code.Namespace, _version.Addressing.Namespace, StringComparison.Ordinal) == 0)
                    {
                        if (string.Compare(code.Name, AddressingStrings.EndpointUnavailable, StringComparison.Ordinal) == 0)
                        {
                            exception = new ServerTooBusyException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                            return true;
                        }
                    }
                }

                return false;
            }
Beispiel #30
0
        void GotResponse(IAsyncResult result)
        {
            HttpChannelRequestAsyncResult channelResult = (HttpChannelRequestAsyncResult)result.AsyncState;

            channelResult.CompletedSynchronously &= result.CompletedSynchronously;

            WebResponse res;
            Stream      resstr;

            try
            {
                res    = channelResult.WebRequest.EndGetResponse(result);
                resstr = res.GetResponseStream();
            }
            catch (WebException we)
            {
                res = we.Response;
                if (res == null)
                {
                    channelResult.Complete(we);
                    return;
                }


                var hrr2 = (HttpWebResponse)res;

                if ((int)hrr2.StatusCode >= 400 && (int)hrr2.StatusCode < 500)
                {
                    Exception exception = new WebException(
                        String.Format("There was an error on processing web request: Status code {0}({1}): {2}",
                                      (int)hrr2.StatusCode, hrr2.StatusCode, hrr2.StatusDescription), null,
                        WebExceptionStatus.ProtocolError, hrr2);

                    if ((int)hrr2.StatusCode == 404)
                    {
                        // Throw the same exception .NET does
                        exception = new EndpointNotFoundException(
                            "There was no endpoint listening at {0} that could accept the message. This is often caused by an incorrect address " +
                            "or SOAP action. See InnerException, if present, for more details.",
                            exception);
                    }

                    channelResult.Complete(exception);
                    return;
                }


                try
                {
                    // The response might contain SOAP fault. It might not.
                    resstr = res.GetResponseStream();
                }
                catch (WebException we2)
                {
                    channelResult.Complete(we2);
                    return;
                }
            }

            var hrr = (HttpWebResponse)res;

            if ((int)hrr.StatusCode >= 400 && (int)hrr.StatusCode < 500)
            {
                channelResult.Complete(new WebException(String.Format("There was an error on processing web request: Status code {0}({1}): {2}", (int)hrr.StatusCode, hrr.StatusCode, hrr.StatusDescription)));
            }

            try
            {
                Message ret;

                // TODO: unit test to make sure an empty response never throws
                // an exception at this level
                if (hrr.ContentLength == 0)
                {
                    ret = Message.CreateMessage(Encoder.MessageVersion, String.Empty);
                }
                else
                {
                    using (var responseStream = resstr)
                    {
                        MemoryStream ms = new MemoryStream();
                        byte []      b  = new byte [65536];
                        int          n  = 0;

                        while (true)
                        {
                            n = responseStream.Read(b, 0, 65536);
                            if (n == 0)
                            {
                                break;
                            }
                            ms.Write(b, 0, n);
                        }
                        ms.Seek(0, SeekOrigin.Begin);

                        ret = Encoder.ReadMessage(
                            ms, (int)source.Transport.MaxReceivedMessageSize, res.ContentType);
                    }
                }

                var rp = new HttpResponseMessageProperty()
                {
                    StatusCode = hrr.StatusCode, StatusDescription = hrr.StatusDescription
                };
#if MOONLIGHT
                if (hrr.SupportsHeaders)
                {
                    foreach (string key in hrr.Headers)
                    {
                        rp.Headers [key] = hrr.Headers [key];
                    }
                }
#else
                foreach (var key in hrr.Headers.AllKeys)
                {
                    rp.Headers [key] = hrr.Headers [key];
                }
#endif
                ret.Properties.Add(HttpResponseMessageProperty.Name, rp);

                channelResult.Response = ret;
                channelResult.Complete();
            }
            catch (Exception ex)
            {
                channelResult.Complete(ex);
            }
            finally
            {
                res.Close();
            }
        }
        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();
                }
            }
        }