Example #1
0
        private IMessage DeserializeMessage(IMethodCallMessage mcm, ITransportHeaders headers, Stream stream)
        {
            IMessage message;
            string   str2;
            string   str3;

            Header[] h           = new Header[] { new Header("__TypeName", mcm.TypeName), new Header("__MethodName", mcm.MethodName), new Header("__MethodSignature", mcm.MethodSignature) };
            string   contentType = headers["Content-Type"] as string;

            HttpChannelHelper.ParseContentType(contentType, out str2, out str3);
            if (string.Compare(str2, "text/xml", StringComparison.Ordinal) == 0)
            {
                message = CoreChannel.DeserializeSoapResponseMessage(stream, mcm, h, this._strictBinding);
            }
            else
            {
                int           count   = 0x400;
                byte[]        buffer  = new byte[count];
                StringBuilder builder = new StringBuilder();
                for (int i = stream.Read(buffer, 0, count); i > 0; i = stream.Read(buffer, 0, count))
                {
                    builder.Append(Encoding.ASCII.GetString(buffer, 0, i));
                }
                message = new ReturnMessage(new RemotingException(builder.ToString()), mcm);
            }
            stream.Close();
            return(message);
        }
Example #2
0
        private void SerializeMessage(IMethodCallMessage mcm, out ITransportHeaders headers, out Stream stream)
        {
            BaseTransportHeaders headers2 = new BaseTransportHeaders();

            headers = headers2;
            MethodBase methodBase = mcm.MethodBase;

            headers["SOAPAction"] = '"' + HttpEncodingHelper.EncodeUriAsXLinkHref(SoapServices.GetSoapActionFromMethodBase(methodBase)) + '"';
            headers2.ContentType  = "text/xml; charset=\"utf-8\"";
            if (this._channelProtocol == SinkChannelProtocol.Http)
            {
                headers["__RequestVerb"] = "POST";
            }
            bool flag = false;

            stream = this._nextSink.GetRequestStream(mcm, headers);
            if (stream == null)
            {
                stream = new ChunkedMemoryStream(CoreChannel.BufferPool);
                flag   = true;
            }
            CoreChannel.SerializeSoapMessage(mcm, stream, this._includeVersioning);
            if (flag)
            {
                stream.Position = 0L;
            }
        }
Example #3
0
        } // EndAsyncCopyStream

        private static void AsyncCopyReadHelper(AsyncCopyStreamResult streamState)
        {
            // There is no try-catch here because the calling method always has a try-catch.

            if (streamState.AsyncRead)
            {
                byte[] buffer = streamState.Buffer;
                streamState.Source.BeginRead(buffer, 0, buffer.Length, _asyncCopyStreamReadCallback, streamState);
            }
            else
            {
                byte[] buffer    = streamState.Buffer;
                int    bytesRead = streamState.Source.Read(buffer, 0, buffer.Length);
                if (bytesRead == 0)
                {
                    streamState.SetComplete(null, null);
                }
                else
                if (bytesRead < 0)
                {
                    throw new RemotingException(
                              CoreChannel.GetResourceString("Remoting_Stream_UnknownReadError"));
                }
                else
                {
                    AsyncCopyWriteHelper(streamState, bytesRead);
                }
            }
        } // AsyncCopyReadHelper
        } // BinaryServerFormatterSinkProvider

        public BinaryServerFormatterSinkProvider(IDictionary properties, ICollection providerData)
        {
            // look at properties
            if (properties != null)
            {
                foreach (DictionaryEntry entry in properties)
                {
                    String keyStr = entry.Key.ToString();
                    switch (keyStr)
                    {
                    case "includeVersions": _includeVersioning = Convert.ToBoolean(entry.Value, CultureInfo.InvariantCulture); break;

                    case "strictBinding": _strictBinding = Convert.ToBoolean(entry.Value, CultureInfo.InvariantCulture); break;

                    case "typeFilterLevel":
                        _formatterSecurityLevel = (TypeFilterLevel)Enum.Parse(typeof(TypeFilterLevel), (string)entry.Value);
                        break;

                    default:
                        break;
                    }
                }
            }

            // not expecting any provider data
            CoreChannel.VerifyNoProviderData(this.GetType().Name, providerData);
        } // BinaryServerFormatterSinkProvider
Example #5
0
        }         // BufferCopy

        internal static IAsyncResult BeginAsyncCopyStream(
            Stream source, Stream target,
            bool asyncRead, bool asyncWrite,
            bool closeSource, bool closeTarget,
            AsyncCallback callback, Object state)
        {
            AsyncCopyStreamResult streamState = new AsyncCopyStreamResult(callback, state);

            byte[] buffer = CoreChannel.BufferPool.GetBuffer();

            streamState.Source      = source;
            streamState.Target      = target;
            streamState.Buffer      = buffer;
            streamState.AsyncRead   = asyncRead;
            streamState.AsyncWrite  = asyncWrite;
            streamState.CloseSource = closeSource;
            streamState.CloseTarget = closeTarget;

            try
            {
                AsyncCopyReadHelper(streamState);
            }
            catch (Exception e)
            {
                streamState.SetComplete(null, e);
            }
            catch {
                streamState.SetComplete(null, new Exception(CoreChannel.GetResourceString("Remoting_nonClsCompliantException")));
            }

            return(streamState);
        } // BeginAsyncCopyStream
Example #6
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (this._bClosed)
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }
            if (this._chunks == null)
            {
                this._chunks      = this.AllocateMemoryChunk();
                this._writeChunk  = this._chunks;
                this._writeOffset = 0;
            }
            byte[] dst    = this._writeChunk.Buffer;
            int    length = dst.Length;

            while (count > 0)
            {
                if (this._writeOffset == length)
                {
                    this._writeChunk.Next = this.AllocateMemoryChunk();
                    this._writeChunk      = this._writeChunk.Next;
                    this._writeOffset     = 0;
                    dst    = this._writeChunk.Buffer;
                    length = dst.Length;
                }
                int num2 = Math.Min(count, length - this._writeOffset);
                Buffer.BlockCopy(buffer, offset, dst, this._writeOffset, num2);
                offset            += num2;
                count             -= num2;
                this._writeOffset += num2;
            }
        }
Example #7
0
        public IMessage SyncProcessMessage(IMessage msg)
        {
            IMethodCallMessage mcm = (IMethodCallMessage)msg;
            IMessage           retMsg;

            try
            {
                // serialize message
                ITransportHeaders headers;
                Stream            requestStream;
                SerializeMessage(mcm, out headers, out requestStream);

                // process message
                Stream            returnStream;
                ITransportHeaders returnHeaders;
                _nextSink.ProcessMessage(msg, headers, requestStream,
                                         out returnHeaders, out returnStream);
                if (returnHeaders == null)
                {
                    throw new ArgumentNullException("returnHeaders");
                }

                // deserialize stream
                retMsg = DeserializeMessage(mcm, returnHeaders, returnStream);
            }
            catch (Exception e)
            {
                retMsg = new ReturnMessage(e, mcm);
            }
            catch {
                retMsg = new ReturnMessage(new Exception(CoreChannel.GetResourceString("Remoting_nonClsCompliantException")), mcm);
            }

            return(retMsg);
        } // SyncProcessMessage
Example #8
0
        public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
        {
            IMethodCallMessage mcm = (IMethodCallMessage)msg;
            IMessage           retMsg;

            try
            {
                // serialize message
                ITransportHeaders headers;
                Stream            requestStream;
                SerializeMessage(mcm, out headers, out requestStream);

                // process message
                ClientChannelSinkStack sinkStack = new ClientChannelSinkStack(replySink);
                sinkStack.Push(this, mcm);
                _nextSink.AsyncProcessRequest(sinkStack, msg, headers, requestStream);
            }
            catch (Exception e)
            {
                retMsg = new ReturnMessage(e, mcm);
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(retMsg);
                }
            }
            catch {
                retMsg = new ReturnMessage(new Exception(CoreChannel.GetResourceString("Remoting_nonClsCompliantException")), mcm);
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(retMsg);
                }
            }

            return(null);
        } // AsyncProcessMessage
        private static void AsyncCopyStreamReadCallback(IAsyncResult iar)
        {
            AsyncCopyStreamResult asyncState = (AsyncCopyStreamResult)iar.AsyncState;

            try
            {
                int bytesRead = asyncState.Source.EndRead(iar);
                if (bytesRead == 0)
                {
                    asyncState.SetComplete(null, null);
                }
                else
                {
                    if (bytesRead < 0)
                    {
                        throw new RemotingException(CoreChannel.GetResourceString("Remoting_Stream_UnknownReadError"));
                    }
                    AsyncCopyWriteHelper(asyncState, bytesRead);
                }
            }
            catch (Exception exception)
            {
                asyncState.SetComplete(null, exception);
            }
        }
 private static void AsyncCopyReadHelper(AsyncCopyStreamResult streamState)
 {
     if (streamState.AsyncRead)
     {
         byte[] buffer = streamState.Buffer;
         streamState.Source.BeginRead(buffer, 0, buffer.Length, _asyncCopyStreamReadCallback, streamState);
     }
     else
     {
         byte[] buffer2   = streamState.Buffer;
         int    bytesRead = streamState.Source.Read(buffer2, 0, buffer2.Length);
         if (bytesRead == 0)
         {
             streamState.SetComplete(null, null);
         }
         else
         {
             if (bytesRead < 0)
             {
                 throw new RemotingException(CoreChannel.GetResourceString("Remoting_Stream_UnknownReadError"));
             }
             AsyncCopyWriteHelper(streamState, bytesRead);
         }
     }
 }
        private Header[] GetChannelHeaders(ITransportHeaders requestHeaders, out string soapActionToVerify)
        {
            string str3;
            string str4;

            soapActionToVerify = null;
            string uRI = (string)requestHeaders["__RequestUri"];
            string uri = (string)requestHeaders["SOAPAction"];

            if (uri == null)
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_SoapActionMissing"));
            }
            uri = HttpEncodingHelper.DecodeUri(uri);
            soapActionToVerify = uri;
            if (!SoapServices.GetTypeAndMethodNameFromSoapAction(uri, out str3, out str4))
            {
                Type serverTypeForUri = RemotingServices.GetServerTypeForUri(uRI);
                if (serverTypeForUri == null)
                {
                    throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_TypeNotFoundFromUri"), new object[] { uRI }));
                }
                str3 = "clr:" + serverTypeForUri.FullName + ", " + serverTypeForUri.Assembly.GetName().Name;
            }
            else
            {
                str3 = "clr:" + str3;
            }
            int num = 2;

            Header[] headerArray = new Header[num];
            headerArray[0] = new Header("__Uri", uRI);
            headerArray[1] = new Header("__TypeName", str3);
            return(headerArray);
        }
Example #12
0
        public BinaryClientFormatterSinkProvider(IDictionary properties, ICollection providerData)
        {
            this._includeVersioning = true;
            if (properties != null)
            {
                foreach (DictionaryEntry entry in properties)
                {
                    string str2 = entry.Key.ToString();
                    if (str2 != null)
                    {
                        if (!(str2 == "includeVersions"))
                        {
                            if (str2 == "strictBinding")
                            {
                                goto Label_006F;
                            }
                        }
                        else
                        {
                            this._includeVersioning = Convert.ToBoolean(entry.Value, CultureInfo.InvariantCulture);
                        }
                    }
                    continue;
Label_006F:
                    this._strictBinding = Convert.ToBoolean(entry.Value, CultureInfo.InvariantCulture);
                }
            }
            CoreChannel.VerifyNoProviderData(base.GetType().Name, providerData);
        }
Example #13
0
        } // AsyncCopyWriteHelper

        private static void AsyncCopyStreamReadCallback(IAsyncResult iar)
        {
            AsyncCopyStreamResult state = (AsyncCopyStreamResult)iar.AsyncState;

            try
            {
                Stream source = state.Source;

                int bytesRead = source.EndRead(iar);
                if (bytesRead == 0)
                {
                    state.SetComplete(null, null);
                }
                else
                if (bytesRead < 0)
                {
                    throw new RemotingException(
                              CoreChannel.GetResourceString("Remoting_Stream_UnknownReadError"));
                }
                else
                {
                    AsyncCopyWriteHelper(state, bytesRead);
                }
            }
            catch (Exception e)
            {
                state.SetComplete(null, e);
            }
            catch {
                state.SetComplete(null, new Exception(CoreChannel.GetResourceString("Remoting_nonClsCompliantException")));
            }
        } // AsyncCopyStreamReadCallback
        } // ToArray

        // write remainder of this stream to another stream
        public virtual void WriteTo(Stream stream)
        {
            if (_bClosed)
            {
                throw new RemotingException(
                          CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }

            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (_readChunk == null)
            {
                if (_chunks == null)
                {
                    return;
                }

                _readChunk  = _chunks;
                _readOffset = 0;
            }

            byte[] chunkBuffer = _readChunk.Buffer;
            int    chunkSize   = chunkBuffer.Length;

            if (_readChunk.Next == null)
            {
                chunkSize = _writeOffset;
            }

            // following code mirrors Read() logic (_readChunk/_readOffset should
            //   point just past last byte of last chunk when done)

            for (;;) // loop until end of chunks is found
            {
                if (_readOffset == chunkSize)
                {
                    // exit if no more chunks are currently available
                    if (_readChunk.Next == null)
                    {
                        break;
                    }

                    _readChunk  = _readChunk.Next;
                    _readOffset = 0;
                    chunkBuffer = _readChunk.Buffer;
                    chunkSize   = chunkBuffer.Length;
                    if (_readChunk.Next == null)
                    {
                        chunkSize = _writeOffset;
                    }
                }

                int writeCount = chunkSize - _readOffset;
                stream.Write(chunkBuffer, _readOffset, writeCount);
                _readOffset = chunkSize;
            }
        } // WriteTo
        } // Write

        public override void WriteByte(byte value)
        {
            if (_bClosed)
            {
                throw new RemotingException(
                          CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }

            if (_chunks == null)
            {
                _chunks      = AllocateMemoryChunk();
                _writeChunk  = _chunks;
                _writeOffset = 0;
            }

            byte[] chunkBuffer = _writeChunk.Buffer;
            int    chunkSize   = chunkBuffer.Length;

            if (_writeOffset == chunkSize)
            {
                // allocate a new chunk if the current one is full
                _writeChunk.Next = AllocateMemoryChunk();
                _writeChunk      = _writeChunk.Next;
                _writeOffset     = 0;
                chunkBuffer      = _writeChunk.Buffer;
                chunkSize        = chunkBuffer.Length;
            }

            chunkBuffer[_writeOffset++] = value;
        } // WriteByte
        } // Position

        public override long Seek(long offset, SeekOrigin origin)
        {
            if (_bClosed)
            {
                throw new RemotingException(
                          CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }

            switch (origin)
            {
            case SeekOrigin.Begin:
                Position = offset;
                break;

            case SeekOrigin.Current:
                Position = Position + offset;
                break;

            case SeekOrigin.End:
                Position = Length + offset;
                break;
            }

            return(Position);
        } // Seek
Example #17
0
        /// <include file='doc\SoapFormatterSinks.uex' path='docs/doc[@for="SoapClientFormatterSinkProvider.SoapClientFormatterSinkProvider1"]/*' />
        public SoapClientFormatterSinkProvider(IDictionary properties, ICollection providerData)
        {
            // look at properties
            if (properties != null)
            {
                foreach (DictionaryEntry entry in properties)
                {
                    String keyStr = entry.Key.ToString();
                    switch (keyStr)
                    {
                    case "includeVersions": _includeVersioning = Convert.ToBoolean(entry.Value); break;

                    case "strictBinding": _strictBinding = Convert.ToBoolean(entry.Value); break;

                    default:
                        CoreChannel.ReportUnknownProviderConfigProperty(
                            this.GetType().Name, keyStr);
                        break;
                    }
                }
            }

            // not expecting any provider data
            CoreChannel.VerifyNoProviderData(this.GetType().Name, providerData);
        }
        } // AsyncProcessMessage

        // helper function to serialize the message
        private void SerializeMessage(IMessage msg,
                                      out ITransportHeaders headers, out Stream stream)
        {
            BaseTransportHeaders requestHeaders = new BaseTransportHeaders();

            headers = requestHeaders;

            // add other http soap headers
            requestHeaders.ContentType = CoreChannel.BinaryMimeType;
            if (_channelProtocol == SinkChannelProtocol.Http)
            {
                headers["__RequestVerb"] = "POST";
            }

            bool bMemStream = false;

            stream = _nextSink.GetRequestStream(msg, headers);
            if (stream == null)
            {
                stream     = new ChunkedMemoryStream(CoreChannel.BufferPool);
                bMemStream = true;
            }
            CoreChannel.SerializeBinaryMessage(msg, stream, _includeVersioning);
            if (bMemStream)
            {
                stream.Position = 0;
            }
        } // SerializeMessage
        private IMessage DeserializeMessage(IMethodCallMessage mcm, ITransportHeaders headers, Stream stream)
        {
            IMessage message = CoreChannel.DeserializeBinaryResponseMessage(stream, mcm, this._strictBinding);

            stream.Close();
            return(message);
        }
Example #20
0
        public override void WriteByte(byte value)
        {
            if (this._bClosed)
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }
            if (this._chunks == null)
            {
                this._chunks      = this.AllocateMemoryChunk();
                this._writeChunk  = this._chunks;
                this._writeOffset = 0;
            }
            byte[] buffer = this._writeChunk.Buffer;
            int    length = buffer.Length;

            if (this._writeOffset == length)
            {
                this._writeChunk.Next = this.AllocateMemoryChunk();
                this._writeChunk      = this._writeChunk.Next;
                this._writeOffset     = 0;
                buffer = this._writeChunk.Buffer;
                length = buffer.Length;
            }
            buffer[this._writeOffset++] = value;
        }
        protected byte[] ReadToByte(byte b, ValidateByteDelegate validator)
        {
            byte[] dest = null;
            if (this._dataCount == 0)
            {
                this.BufferMoreData();
            }
            int  num       = this._dataOffset + this._dataCount;
            int  srcOffset = this._dataOffset;
            int  index     = srcOffset;
            bool flag      = false;

            while (!flag)
            {
                bool flag2 = index == num;
                flag = !flag2 && (this._dataBuffer[index] == b);
                if (((validator != null) && !flag2) && (!flag && !validator(this._dataBuffer[index])))
                {
                    throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_InvalidDataReceived"));
                }
                if (flag2 || flag)
                {
                    int count = index - srcOffset;
                    if (dest == null)
                    {
                        dest = new byte[count];
                        StreamHelper.BufferCopy(this._dataBuffer, srcOffset, dest, 0, count);
                    }
                    else
                    {
                        int    length  = dest.Length;
                        byte[] buffer2 = new byte[length + count];
                        StreamHelper.BufferCopy(dest, 0, buffer2, 0, length);
                        StreamHelper.BufferCopy(this._dataBuffer, srcOffset, buffer2, length, count);
                        dest = buffer2;
                    }
                    this._dataOffset += count;
                    this._dataCount  -= count;
                    if (flag2)
                    {
                        this.BufferMoreData();
                        num       = this._dataOffset + this._dataCount;
                        srcOffset = this._dataOffset;
                        index     = srcOffset;
                    }
                    else if (flag)
                    {
                        this._dataOffset++;
                        this._dataCount--;
                    }
                }
                else
                {
                    index++;
                }
            }
            return(dest);
        }
        } // Flush

        public override int Read(byte[] buffer, int offset, int count)
        {
            if (_bClosed)
            {
                throw new RemotingException(
                          CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }

            if (_readChunk == null)
            {
                if (_chunks == null)
                {
                    return(0);
                }
                _readChunk  = _chunks;
                _readOffset = 0;
            }

            byte[] chunkBuffer = _readChunk.Buffer;
            int    chunkSize   = chunkBuffer.Length;

            if (_readChunk.Next == null)
            {
                chunkSize = _writeOffset;
            }

            int bytesRead = 0;

            while (count > 0)
            {
                if (_readOffset == chunkSize)
                {
                    // exit if no more chunks are currently available
                    if (_readChunk.Next == null)
                    {
                        break;
                    }

                    _readChunk  = _readChunk.Next;
                    _readOffset = 0;
                    chunkBuffer = _readChunk.Buffer;
                    chunkSize   = chunkBuffer.Length;
                    if (_readChunk.Next == null)
                    {
                        chunkSize = _writeOffset;
                    }
                }

                int readCount = Math.Min(count, chunkSize - _readOffset);
                Buffer.BlockCopy(chunkBuffer, _readOffset, buffer, offset, readCount);
                offset      += readCount;
                count       -= readCount;
                _readOffset += readCount;
                bytesRead   += readCount;
            }

            return(bytesRead);
        } // Read
Example #23
0
        } // VerifyNoProviderData

        internal static void ReportUnknownProviderConfigProperty(String providerTypeName,
                                                                 String propertyName)
        {
            throw new RemotingException(
                      String.Format(
                          CoreChannel.GetResourceString(
                              "Remoting_Providers_Config_UnknownProperty"),
                          providerTypeName, propertyName));
        } // ReportUnknownProviderConfigProperty
        } // SerializeMessage

        // helper function to deserialize the message
        private IMessage DeserializeMessage(IMethodCallMessage mcm,
                                            ITransportHeaders headers, Stream stream)
        {
            // deserialize the message
            IMessage retMsg = CoreChannel.DeserializeBinaryResponseMessage(stream, mcm, _strictBinding);

            stream.Close();
            return(retMsg);
        } // DeserializeMessage
Example #25
0
        } // AsyncProcessResponse

        private void SerializeResponse(IServerResponseChannelSinkStack sinkStack,
                                       IMessage msg, bool bClientIsClr, ref ITransportHeaders headers,
                                       out Stream stream)
        {
            BaseTransportHeaders responseHeaders = new BaseTransportHeaders();

            if (headers != null)
            {
                // copy old headers into new headers
                foreach (DictionaryEntry entry in headers)
                {
                    responseHeaders[entry.Key] = entry.Value;
                }
            }
            headers = responseHeaders;
            responseHeaders.ContentType = CoreChannel.SOAPContentType;

            if (_protocol == Protocol.Http)
            {
                // check to see if an exception occurred (requires special status code for HTTP)
                IMethodReturnMessage mrm = msg as IMethodReturnMessage;
                if ((mrm != null) && (mrm.Exception != null))
                {
                    headers["__HttpStatusCode"]   = "500";
                    headers["__HttpReasonPhrase"] = "Internal Server Error";
                }
            }

            bool bMemStream = false;

            stream = sinkStack.GetResponseStream(msg, headers);
            if (stream == null)
            {
                stream     = new ChunkedMemoryStream(CoreChannel.BufferPool);
                bMemStream = true;
            }


            bool bBashUrl = CoreChannel.SetupUrlBashingForIisSslIfNecessary();

            CallContext.SetData("__ClientIsClr", bClientIsClr);
            try
            {
                CoreChannel.SerializeSoapMessage(msg, stream, _includeVersioning);
            }
            finally
            {
                CallContext.FreeNamedDataSlot("__ClientIsClr");
                CoreChannel.CleanupUrlBashingForIisSslIfNecessary(bBashUrl);
            }

            if (bMemStream)
            {
                stream.Position = 0;
            }
        } // SerializeResponse
        private int ReadFromSocket(byte[] buffer, int offset, int count)
        {
            int num = this.NetStream.Read(buffer, offset, count);

            if (num <= 0)
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_Socket_UnderlyingSocketClosed"));
            }
            return(num);
        }
Example #27
0
        } // ReleaseControl

        // Determines if the remote connection is from localhost.
        internal bool IsLocalhost()
        {
            if (NetSocket == null || NetSocket.RemoteEndPoint == null)
            {
                return(true);
            }

            IPAddress remoteAddr = ((IPEndPoint)NetSocket.RemoteEndPoint).Address;

            return(IPAddress.IsLoopback(remoteAddr) || CoreChannel.IsLocalIpAddress(remoteAddr));
        } // IsLocalhost
Example #28
0
        } // CollectChannelDataFromServerSinkProviders

        // called by providers that aren't expecting custom provider data
        internal static void VerifyNoProviderData(String providerTypeName, ICollection providerData)
        {
            if ((providerData != null) && (providerData.Count > 0))
            {
                throw new RemotingException(
                          String.Format(
                              CoreChannel.GetResourceString(
                                  "Remoting_Providers_Config_NotExpectingProviderData"),
                              providerTypeName));
            }
        } // VerifyNoProviderData
 internal bool IsLocalhost()
 {
     if ((this.NetSocket != null) && (this.NetSocket.RemoteEndPoint != null))
     {
         IPAddress address = ((IPEndPoint)this.NetSocket.RemoteEndPoint).Address;
         if (!IPAddress.IsLoopback(address))
         {
             return(CoreChannel.IsLocalIpAddress(address));
         }
     }
     return(true);
 }
Example #30
0
        } // Properties


        // Helper method for analyzing headers
        private Header[] GetChannelHeaders(ITransportHeaders requestHeaders,
                                           out String soapActionToVerify)
        {
            soapActionToVerify = null;

            // transport sink removes any channel specific information
            String objectURI = (String)requestHeaders[CommonTransportKeys.RequestUri];

            // see if a unique SOAPAction is present (if more than one SOAPAction is present some
            //   scenarios won't work, but one-many soap action to method base relationships are
            //   for interop scenarios only)
            String soapAction = (String)requestHeaders["SOAPAction"];

            if (soapAction == null)
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_SoapActionMissing"));
            }
            soapAction = HttpEncodingHelper.DecodeUri(soapAction);

            soapActionToVerify = soapAction;

            String typeName, methodName;

            if (!SoapServices.GetTypeAndMethodNameFromSoapAction(soapAction, out typeName, out methodName))
            {
                // This means there are multiple methods for this soap action, so we will have to
                // settle for the type based off of the uri.
                Type type = RemotingServices.GetServerTypeForUri(objectURI);
                if (type == null)
                {
                    throw new RemotingException(
                              String.Format(
                                  CultureInfo.CurrentCulture, CoreChannel.GetResourceString(
                                      "Remoting_TypeNotFoundFromUri"), objectURI));
                }

                // @todo: This throws away the version, culture and public key token
                typeName = "clr:" + type.FullName + ", " + type.Assembly.GetName().Name;
            }
            else
            {
                typeName = "clr:" + typeName;
            }

            // Create a new header array and pass it back.
            int headerLen = 2;

            Header[] h = new Header[headerLen];
            h[0] = new Header("__Uri", objectURI);
            h[1] = new Header("__TypeName", typeName);

            return(h);
        } // GetChannelHeaders