} // 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
 internal static void CopyStream(Stream source, Stream target)
 {
     if (source != null)
     {
         ChunkedMemoryStream stream = source as ChunkedMemoryStream;
         if (stream != null)
         {
             stream.WriteTo(target);
         }
         else
         {
             MemoryStream stream2 = source as MemoryStream;
             if (stream2 != null)
             {
                 stream2.WriteTo(target);
             }
             else
             {
                 byte[] buffer = CoreChannel.BufferPool.GetBuffer();
                 int    length = buffer.Length;
                 for (int i = source.Read(buffer, 0, length); i > 0; i = source.Read(buffer, 0, length))
                 {
                     target.Write(buffer, 0, i);
                 }
                 CoreChannel.BufferPool.ReturnBuffer(buffer);
             }
         }
     }
 }
예제 #3
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;
            }
        }
예제 #4
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
        } // AsyncProcessResponse

        private void SerializeResponse(IServerResponseChannelSinkStack sinkStack,
                                       IMessage msg, 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;

            if (_protocol == Protocol.Http)
            {
                responseHeaders.ContentType = CoreChannel.BinaryMimeType;
            }

            bool bMemStream = false;

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


            bool bBashUrl = CoreChannel.SetupUrlBashingForIisSslIfNecessary();

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

            if (bMemStream)
            {
                stream.Position = 0;
            }
        } // SerializeResponse
        private void SerializeResponse(IServerResponseChannelSinkStack sinkStack, IMessage msg, bool bClientIsClr, ref ITransportHeaders headers, out Stream stream)
        {
            BaseTransportHeaders headers2 = new BaseTransportHeaders();

            if (headers != null)
            {
                foreach (DictionaryEntry entry in headers)
                {
                    headers2[entry.Key] = entry.Value;
                }
            }
            headers = headers2;
            headers2.ContentType = "text/xml; charset=\"utf-8\"";
            if (this._protocol == Protocol.Http)
            {
                IMethodReturnMessage message = msg as IMethodReturnMessage;
                if ((message != null) && (message.Exception != null))
                {
                    headers["__HttpStatusCode"]   = "500";
                    headers["__HttpReasonPhrase"] = "Internal Server Error";
                }
            }
            bool flag = false;

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

            CallContext.SetData("__ClientIsClr", bClientIsClr);
            try
            {
                CoreChannel.SerializeSoapMessage(msg, stream, this._includeVersioning);
            }
            finally
            {
                CallContext.FreeNamedDataSlot("__ClientIsClr");
                CoreChannel.CleanupUrlBashingForIisSslIfNecessary(bBashedUrl);
            }
            if (flag)
            {
                stream.Position = 0L;
            }
        }
        private void SerializeResponse(IServerResponseChannelSinkStack sinkStack, IMessage msg, ref ITransportHeaders headers, out Stream stream)
        {
            BaseTransportHeaders headers2 = new BaseTransportHeaders();

            if (headers != null)
            {
                foreach (DictionaryEntry entry in headers)
                {
                    headers2[entry.Key] = entry.Value;
                }
            }
            headers = headers2;
            if (this._protocol == Protocol.Http)
            {
                headers2.ContentType = "application/octet-stream";
            }
            bool flag = false;

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

            try
            {
                CallContext.SetData("__ClientIsClr", true);
                CoreChannel.SerializeBinaryMessage(msg, stream, this._includeVersioning);
            }
            finally
            {
                CallContext.FreeNamedDataSlot("__ClientIsClr");
                CoreChannel.CleanupUrlBashingForIisSslIfNecessary(bBashedUrl);
            }
            if (flag)
            {
                stream.Position = 0L;
            }
        }
예제 #8
0
        internal static void CopyStream(Stream source, Stream target)
        {
            if (source == null)
            {
                return;
            }

            // see if this is a ChunkedMemoryStream (we can do a direct write)
            ChunkedMemoryStream chunkedMemStream = source as ChunkedMemoryStream;

            if (chunkedMemStream != null)
            {
                chunkedMemStream.WriteTo(target);
            }
            else
            {
                // see if this is a MemoryStream (we can do a direct write)
                MemoryStream memContentStream = source as MemoryStream;
                if (memContentStream != null)
                {
                    memContentStream.WriteTo(target);
                }
                else
                {
                    // otherwise, we need to copy the data through an intermediate buffer

                    byte[] buffer     = CoreChannel.BufferPool.GetBuffer();
                    int    bufferSize = buffer.Length;
                    int    readCount  = source.Read(buffer, 0, bufferSize);
                    while (readCount > 0)
                    {
                        target.Write(buffer, 0, readCount);
                        readCount = source.Read(buffer, 0, bufferSize);
                    }
                    CoreChannel.BufferPool.ReturnBuffer(buffer);
                }
            }
        } // CopyStream
예제 #9
0
        } // AsyncProcessMessage

        //
        // end of IMessageSink implementation
        //


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

            headers = requestHeaders;

            // add SOAPAction header
            MethodBase mb = mcm.MethodBase;

            headers["SOAPAction"] =
                '"' +
                HttpEncodingHelper.EncodeUriAsXLinkHref(
                    SoapServices.GetSoapActionFromMethodBase(mb)) +
                '"';

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

            bool bMemStream = false;

            stream = _nextSink.GetRequestStream(mcm, headers);
            if (stream == null)
            {
                stream     = new ChunkedMemoryStream(CoreChannel.BufferPool);
                bMemStream = true;
            }
            CoreChannel.SerializeSoapMessage(mcm, stream, _includeVersioning);
            if (bMemStream)
            {
                stream.Position = 0;
            }
        } // SerializeMessage
        private void SerializeMessage(IMessage msg, out ITransportHeaders headers, out Stream stream)
        {
            BaseTransportHeaders headers2 = new BaseTransportHeaders();

            headers = headers2;
            headers2.ContentType = "application/octet-stream";
            if (this._channelProtocol == SinkChannelProtocol.Http)
            {
                headers["__RequestVerb"] = "POST";
            }
            bool flag = false;

            stream = this._nextSink.GetRequestStream(msg, headers);
            if (stream == null)
            {
                stream = new ChunkedMemoryStream(CoreChannel.BufferPool);
                flag   = true;
            }
            CoreChannel.SerializeBinaryMessage(msg, stream, this._includeVersioning);
            if (flag)
            {
                stream.Position = 0L;
            }
        }