} // 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 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; } }
} // 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
public BaseTransportHeaders ReadHeaders() { ushort num; BaseTransportHeaders headers = new BaseTransportHeaders(); base.ReadVersionAndOperation(out num); if (num != 2) { throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_ExpectingReplyOp"), new object[] { num.ToString(CultureInfo.CurrentCulture) })); } base.ReadContentLength(out this._bChunked, out this._contentLength); base.ReadToEndOfHeaders(headers); return headers; }
internal ITransportHeaders ReadHeaders() { ushort num; BaseTransportHeaders headers = new BaseTransportHeaders(); base.ReadVersionAndOperation(out num); if (num == 1) { this._bOneWayRequest = true; } bool chunked = false; base.ReadContentLength(out chunked, out this._contentLength); this.ReadToEndOfHeaders(headers); return headers; }
} // 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; } }
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; } }
public void HandleRequest(HttpContext context) { IMessage message; ITransportHeaders headers2; Stream stream2; HttpRequest request = context.Request; HttpResponse httpResponse = context.Response; BaseTransportHeaders requestHeaders = new BaseTransportHeaders(); requestHeaders["__RequestVerb"] = request.HttpMethod; requestHeaders["__CustomErrorsEnabled"] = HttpRemotingHandler.CustomErrorsEnabled(context); requestHeaders.RequestUri = (string) context.Items["__requestUri"]; NameValueCollection headers = request.Headers; foreach (string str in headers.AllKeys) { string str2 = headers[str]; requestHeaders[str] = str2; } requestHeaders.IPAddress = IPAddress.Parse(request.UserHostAddress); Stream inputStream = request.InputStream; ServerChannelSinkStack sinkStack = new ServerChannelSinkStack(); sinkStack.Push(this, null); switch (this._nextSink.ProcessMessage(sinkStack, null, requestHeaders, inputStream, out message, out headers2, out stream2)) { case ServerProcessing.Complete: this.SendResponse(httpResponse, 200, headers2, stream2); return; case ServerProcessing.OneWay: this.SendResponse(httpResponse, 0xca, headers2, stream2); break; case ServerProcessing.Async: break; default: return; } }
} // 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
public ITransportHeaders ReadHeaders() { ushort num; BaseTransportHeaders headers = new BaseTransportHeaders(); base.ReadVersionAndOperation(out num); switch (num) { case 0: this._bOneWayRequest = false; break; case 1: this._bOneWayRequest = true; break; default: throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_ExpectingRequestOp"), new object[] { num.ToString(CultureInfo.CurrentCulture) })); } base.ReadContentLength(out this._bChunked, out this._contentLength); base.ReadToEndOfHeaders(headers); headers.IPAddress = ((IPEndPoint) base.NetSocket.RemoteEndPoint).Address; headers.ConnectionId = this._connectionId; return headers; }
public BaseTransportHeadersEnumerator(BaseTransportHeaders headers) { _headers = headers; Reset(); } // BaseTransportHeadersEnumerator
public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream) { ServerProcessing complete; if (requestMsg != null) { return(this._nextSink.ProcessMessage(sinkStack, requestMsg, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream)); } if (requestHeaders == null) { throw new ArgumentNullException("requestHeaders"); } BaseTransportHeaders headers = requestHeaders as BaseTransportHeaders; responseHeaders = null; responseStream = null; string str = null; string str2 = null; bool flag = true; string contentType = null; if (headers != null) { contentType = headers.ContentType; } else { contentType = requestHeaders["Content-Type"] as string; } if (contentType != null) { string str4; HttpChannelHelper.ParseContentType(contentType, out str2, out str4); } if ((str2 != null) && (string.Compare(str2, "text/xml", StringComparison.Ordinal) != 0)) { flag = false; } if (this._protocol == Protocol.Http) { str = (string)requestHeaders["__RequestVerb"]; if (!str.Equals("POST") && !str.Equals("M-POST")) { flag = false; } } if (!flag) { if (this._nextSink != null) { return(this._nextSink.ProcessMessage(sinkStack, null, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream)); } if (this._protocol != Protocol.Http) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_Channels_InvalidRequestFormat")); } responseHeaders = new TransportHeaders(); responseHeaders["__HttpStatusCode"] = "400"; responseHeaders["__HttpReasonPhrase"] = "Bad Request"; responseStream = null; responseMsg = null; return(ServerProcessing.Complete); } bool bClientIsClr = true; try { string str7; string uRI = null; if (headers != null) { uRI = headers.RequestUri; } else { uRI = (string)requestHeaders["__RequestUri"]; } if (RemotingServices.GetServerTypeForUri(uRI) == null) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_ChnlSink_UriNotPublished")); } if (this._protocol == Protocol.Http) { string str6 = (string)requestHeaders["User-Agent"]; if (str6 != null) { if (str6.IndexOf("MS .NET Remoting") == -1) { bClientIsClr = false; } } else { bClientIsClr = false; } } bool data = true; object obj2 = requestHeaders["__CustomErrorsEnabled"]; if ((obj2 != null) && (obj2 is bool)) { data = (bool)obj2; } CallContext.SetData("__CustomErrorsEnabled", data); Header[] channelHeaders = this.GetChannelHeaders(requestHeaders, out str7); PermissionSet set = null; if (this.TypeFilterLevel != System.Runtime.Serialization.Formatters.TypeFilterLevel.Full) { set = new PermissionSet(PermissionState.None); set.SetPermission(new SecurityPermission(SecurityPermissionFlag.SerializationFormatter)); } try { if (set != null) { set.PermitOnly(); } requestMsg = CoreChannel.DeserializeSoapRequestMessage(requestStream, channelHeaders, this._strictBinding, this.TypeFilterLevel); } finally { if (set != null) { CodeAccessPermission.RevertPermitOnly(); } } requestStream.Close(); if (requestMsg == null) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_DeserializeMessage")); } if ((str7 != null) && !SoapServices.IsSoapActionValidForMethodBase(str7, ((IMethodMessage)requestMsg).MethodBase)) { throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Soap_InvalidSoapAction"), new object[] { str7 })); } sinkStack.Push(this, null); complete = this._nextSink.ProcessMessage(sinkStack, requestMsg, requestHeaders, null, out responseMsg, out responseHeaders, out responseStream); if (responseStream != null) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_ChnlSink_WantNullResponseStream")); } switch (complete) { case ServerProcessing.Complete: if (responseMsg == null) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_DispatchMessage")); } break; case ServerProcessing.OneWay: sinkStack.Pop(this); return(complete); case ServerProcessing.Async: sinkStack.Store(this, null); return(complete); default: return(complete); } sinkStack.Pop(this); this.SerializeResponse(sinkStack, responseMsg, bClientIsClr, ref responseHeaders, out responseStream); return(complete); } catch (Exception exception) { complete = ServerProcessing.Complete; responseMsg = new ReturnMessage(exception, (requestMsg == null) ? ((IMethodCallMessage) new System.Runtime.Remoting.Channels.Http.ErrorMessage()) : ((IMethodCallMessage)requestMsg)); CallContext.SetData("__ClientIsClr", bClientIsClr); responseStream = (MemoryStream)CoreChannel.SerializeSoapMessage(responseMsg, this._includeVersioning); CallContext.FreeNamedDataSlot("__ClientIsClr"); responseStream.Position = 0L; responseHeaders = new TransportHeaders(); if (this._protocol == Protocol.Http) { responseHeaders["__HttpStatusCode"] = "500"; responseHeaders["__HttpReasonPhrase"] = "Internal Server Error"; responseHeaders["Content-Type"] = "text/xml; charset=\"utf-8\""; } } finally { CallContext.FreeNamedDataSlot("__CustomErrorsEnabled"); } return(complete); }
} // StrictBinding /// <include file='doc\SoapFormatterSinks.uex' path='docs/doc[@for="SoapServerFormatterSink.ProcessMessage"]/*' /> public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream) { if (requestMsg != null) { // The message has already been deserialized so delegate to the next sink. return(_nextSink.ProcessMessage( sinkStack, requestMsg, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream)); } if (requestHeaders == null) { throw new ArgumentNullException("requestHeaders"); } BaseTransportHeaders wkRequestHeaders = requestHeaders as BaseTransportHeaders; ServerProcessing processing; responseHeaders = null; responseStream = null; String verb = null; String contentType = null; bool bCanServiceRequest = true; // determine the content type String contentTypeHeader = null; if (wkRequestHeaders != null) { contentTypeHeader = wkRequestHeaders.ContentType; } else { contentTypeHeader = requestHeaders["Content-Type"] as String; } if (contentTypeHeader != null) { String charsetValue; HttpChannelHelper.ParseContentType(contentTypeHeader, out contentType, out charsetValue); } // check to see if Content-Type matches if ((contentType != null) && (String.Compare(contentType, CoreChannel.SOAPMimeType, false, CultureInfo.InvariantCulture) != 0)) { bCanServiceRequest = false; } // check for http specific verbs if (_protocol == Protocol.Http) { verb = (String)requestHeaders["__RequestVerb"]; if (!verb.Equals("POST") && !verb.Equals("M-POST")) { bCanServiceRequest = false; } } // either delegate or return an error message if we can't service the request if (!bCanServiceRequest) { // delegate to next sink if available if (_nextSink != null) { return(_nextSink.ProcessMessage(sinkStack, null, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream)); } else { // send back an error message if (_protocol == Protocol.Http) { // return a client bad request error responseHeaders = new TransportHeaders(); responseHeaders["__HttpStatusCode"] = "400"; responseHeaders["__HttpReasonPhrase"] = "Bad Request"; responseStream = null; responseMsg = null; return(ServerProcessing.Complete); } else { // The transport sink will catch this and do something here. throw new RemotingException( CoreChannel.GetResourceString("Remoting_Channels_InvalidRequestFormat")); } } } bool bClientIsClr = true; try { String objectUri = null; if (wkRequestHeaders != null) { objectUri = wkRequestHeaders.RequestUri; } else { objectUri = (String)requestHeaders[CommonTransportKeys.RequestUri]; } if (RemotingServices.GetServerTypeForUri(objectUri) == null) { throw new RemotingException( CoreChannel.GetResourceString("Remoting_ChnlSink_UriNotPublished")); } if (_protocol == Protocol.Http) { String userAgent = (String)requestHeaders["User-Agent"]; if (userAgent != null) { if (userAgent.IndexOf("MS .NET Remoting") == -1) { // user agent string did not contain ".NET Remoting", so it is someone else bClientIsClr = false; } } else { bClientIsClr = false; } } // Deserialize Request - Stream to IMessage String soapActionToVerify; Header[] h = GetChannelHeaders(requestHeaders, out soapActionToVerify); requestMsg = CoreChannel.DeserializeSoapRequestMessage(requestStream, h, _strictBinding); requestStream.Close(); if (requestMsg == null) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_DeserializeMessage")); } // verify soap action if necessary if ((soapActionToVerify != null) && (!SoapServices.IsSoapActionValidForMethodBase( soapActionToVerify, ((IMethodMessage)requestMsg).MethodBase))) { throw new RemotingException( String.Format( CoreChannel.GetResourceString("Remoting_Soap_InvalidSoapAction"), soapActionToVerify) ); } // Dispatch Call sinkStack.Push(this, null); processing = _nextSink.ProcessMessage(sinkStack, requestMsg, requestHeaders, null, out responseMsg, out responseHeaders, out responseStream); // make sure that responseStream is null if (responseStream != null) { throw new RemotingException( CoreChannel.GetResourceString("Remoting_ChnlSink_WantNullResponseStream")); } switch (processing) { case ServerProcessing.Complete: { if (responseMsg == null) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_DispatchMessage")); } sinkStack.Pop(this); SerializeResponse(sinkStack, responseMsg, bClientIsClr, ref responseHeaders, out responseStream); break; } // case ServerProcessing.Complete case ServerProcessing.OneWay: { sinkStack.Pop(this); break; } // case ServerProcessing.OneWay: case ServerProcessing.Async: { sinkStack.Store(this, null); break; } // case ServerProcessing.Async } // switch (processing) } catch (Exception e) { processing = ServerProcessing.Complete; responseMsg = new ReturnMessage(e, (IMethodCallMessage)(requestMsg == null?new ErrorMessage():requestMsg)); CallContext.SetData("__ClientIsClr", bClientIsClr); responseStream = (MemoryStream)CoreChannel.SerializeSoapMessage(responseMsg, _includeVersioning); CallContext.FreeNamedDataSlot("__ClientIsClr"); responseStream.Position = 0; responseHeaders = new TransportHeaders(); if (_protocol == Protocol.Http) { responseHeaders["__HttpStatusCode"] = "500"; responseHeaders["__HttpReasonPhrase"] = "Internal Server Error"; responseHeaders["Content-Type"] = CoreChannel.SOAPContentType; } } return(processing); } // ProcessMessage
} // 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
} // 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
} // ValidateVerbCharacter // read headers public BaseTransportHeaders ReadHeaders() { bool bSendContinue = false; BaseTransportHeaders headers = new BaseTransportHeaders(); // read first line String verb, requestURI, version; ReadFirstLine(out verb, out requestURI, out version); if ((verb == null) || (requestURI == null) || (version == null)) { throw new RemotingException( CoreChannel.GetResourceString( "Remoting_Http_UnableToReadFirstLine")); } if (version.Equals("HTTP/1.1")) // most common case _version = HttpVersion.V1_1; else if (version.Equals("HTTP/1.0")) _version = HttpVersion.V1_0; else _version = HttpVersion.V1_1; // (assume it will understand 1.1) if (_version == HttpVersion.V1_1) { _keepAlive = true; } else // it's a 1.0 client { _keepAlive = false; } // update request uri to be sure that it has no channel data String channelURI; String objectURI; channelURI = HttpChannelHelper.ParseURL(requestURI, out objectURI); if (channelURI == null) { objectURI = requestURI; } headers["__RequestVerb"] = verb; headers.RequestUri = objectURI; headers["__HttpVersion"] = version; // check to see if we must send continue if ((_version == HttpVersion.V1_1) && (verb.Equals("POST") || verb.Equals("PUT"))) { bSendContinue = true; } ReadToEndOfHeaders(headers, out _chunkedEncoding, out _contentLength, ref _keepAlive, ref bSendContinue); if (bSendContinue && (_version != HttpVersion.V1_0)) SendContinue(); // add IP address and Connection Id to headers headers[CommonTransportKeys.IPAddress] = ((IPEndPoint)NetSocket.RemoteEndPoint).Address; headers[CommonTransportKeys.ConnectionId] = _connectionId; return headers; } // ReadHeaders
} // StrictBinding /// <include file='doc\BinaryFormatterSinks.uex' path='docs/doc[@for="BinaryServerFormatterSink.ProcessMessage"]/*' /> public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream) { if (requestMsg != null) { // The message has already been deserialized so delegate to the next sink. return(_nextSink.ProcessMessage( sinkStack, requestMsg, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream)); } if (requestHeaders == null) { throw new ArgumentNullException("requestHeaders"); } BaseTransportHeaders wkRequestHeaders = requestHeaders as BaseTransportHeaders; ServerProcessing processing; responseHeaders = null; responseStream = null; String verb = null; String contentType = null; bool bCanServiceRequest = true; // determine the content type String contentTypeHeader = null; if (wkRequestHeaders != null) { contentTypeHeader = wkRequestHeaders.ContentType; } else { contentTypeHeader = requestHeaders["Content-Type"] as String; } if (contentTypeHeader != null) { String charsetValue; HttpChannelHelper.ParseContentType(contentTypeHeader, out contentType, out charsetValue); } // check to see if Content-Type matches if ((contentType != null) && (String.CompareOrdinal(contentType, CoreChannel.BinaryMimeType) != 0)) { bCanServiceRequest = false; } // check for http specific verbs if (_protocol == Protocol.Http) { verb = (String)requestHeaders["__RequestVerb"]; if (!verb.Equals("POST") && !verb.Equals("M-POST")) { bCanServiceRequest = false; } } // either delegate or return an error message if we can't service the request if (!bCanServiceRequest) { // delegate to next sink if available if (_nextSink != null) { return(_nextSink.ProcessMessage(sinkStack, null, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream)); } else { // send back an error message if (_protocol == Protocol.Http) { // return a client bad request error responseHeaders = new TransportHeaders(); responseHeaders["__HttpStatusCode"] = "400"; responseHeaders["__HttpReasonPhrase"] = "Bad Request"; responseStream = null; responseMsg = null; return(ServerProcessing.Complete); } else { // The transport sink will catch this and do something here. throw new RemotingException( CoreChannel.GetResourceString("Remoting_Channels_InvalidRequestFormat")); } } } try { String objectUri = null; if (wkRequestHeaders != null) { objectUri = wkRequestHeaders.RequestUri; } else { objectUri = (String)requestHeaders[CommonTransportKeys.RequestUri]; } if (RemotingServices.GetServerTypeForUri(objectUri) == null) { throw new RemotingException( CoreChannel.GetResourceString("Remoting_ChnlSink_UriNotPublished")); } RemotingServices.LogRemotingStage(CoreChannel.SERVER_MSG_DESER); // Deserialize Request - Stream to IMessage requestMsg = CoreChannel.DeserializeBinaryRequestMessage(objectUri, requestStream, _strictBinding); requestStream.Close(); if (requestMsg == null) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_DeserializeMessage")); } // Dispatch Call sinkStack.Push(this, null); RemotingServices.LogRemotingStage(CoreChannel.SERVER_MSG_SINK_CHAIN); processing = _nextSink.ProcessMessage(sinkStack, requestMsg, requestHeaders, null, out responseMsg, out responseHeaders, out responseStream); // make sure that responseStream is null if (responseStream != null) { throw new RemotingException( CoreChannel.GetResourceString("Remoting_ChnlSink_WantNullResponseStream")); } switch (processing) { case ServerProcessing.Complete: { if (responseMsg == null) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_DispatchMessage")); } sinkStack.Pop(this); RemotingServices.LogRemotingStage(CoreChannel.SERVER_RET_SER); SerializeResponse(sinkStack, responseMsg, ref responseHeaders, out responseStream); break; } // case ServerProcessing.Complete case ServerProcessing.OneWay: { sinkStack.Pop(this); break; } // case ServerProcessing.OneWay: case ServerProcessing.Async: { sinkStack.Store(this, null); break; } // case ServerProcessing.Async } // switch (processing) } catch (Exception e) { processing = ServerProcessing.Complete; responseMsg = new ReturnMessage(e, (IMethodCallMessage)(requestMsg == null?new ErrorMessage():requestMsg)); responseStream = (MemoryStream)CoreChannel.SerializeBinaryMessage(responseMsg, _includeVersioning); responseStream.Position = 0; responseHeaders = new TransportHeaders(); if (_protocol == Protocol.Http) { responseHeaders["Content-Type"] = CoreChannel.BinaryMimeType; } } RemotingServices.LogRemotingStage(CoreChannel.SERVER_RET_SEND); return(processing); } // ProcessMessage
protected void ReadToEndOfHeaders(BaseTransportHeaders headers) { bool flag = false; string str = null; for (ushort i = base.ReadUInt16(); i != 0; i = base.ReadUInt16()) { switch (i) { case 1: { string str2 = base.ReadCountedString(); string str3 = base.ReadCountedString(); headers[str2] = str3; break; } case 4: { string str6; this.ReadAndVerifyHeaderFormat("RequestUri", 1); string url = base.ReadCountedString(); if (IpcChannelHelper.ParseURL(url, out str6) == null) { str6 = url; } headers.RequestUri = str6; break; } case 2: this.ReadAndVerifyHeaderFormat("StatusCode", 3); if (base.ReadUInt16() != 0) { flag = true; } break; case 3: this.ReadAndVerifyHeaderFormat("StatusPhrase", 1); str = base.ReadCountedString(); break; case 6: { this.ReadAndVerifyHeaderFormat("Content-Type", 1); string str7 = base.ReadCountedString(); headers.ContentType = str7; break; } default: { byte num3 = (byte) base.ReadByte(); switch (num3) { case 1: { base.ReadCountedString(); continue; } case 2: { base.ReadByte(); continue; } case 3: { base.ReadUInt16(); continue; } case 4: { base.ReadInt32(); continue; } } throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_UnknownHeaderType"), new object[] { i, num3 })); } } } if (flag) { if (str == null) { str = ""; } throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_GenericServerError"), new object[] { str })); } }
public BaseTransportHeadersEnumerator(BaseTransportHeaders headers) { this._headers = headers; this.Reset(); }
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
public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream) { if (requestMsg != null) { // The message has already been deserialized so delegate to the next sink. return(_nextSink.ProcessMessage( sinkStack, requestMsg, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream)); } if (requestHeaders == null) { throw new ArgumentNullException("requestHeaders"); } BaseTransportHeaders wkRequestHeaders = requestHeaders as BaseTransportHeaders; ServerProcessing processing; responseHeaders = null; responseStream = null; String verb = null; String contentType = null; bool bCanServiceRequest = true; // determine the content type String contentTypeHeader = null; if (wkRequestHeaders != null) { contentTypeHeader = wkRequestHeaders.ContentType; } else { contentTypeHeader = requestHeaders["Content-Type"] as String; } if (contentTypeHeader != null) { String charsetValue; HttpChannelHelper.ParseContentType(contentTypeHeader, out contentType, out charsetValue); } // check to see if Content-Type matches if ((contentType != null) && (String.CompareOrdinal(contentType, CoreChannel.BinaryMimeType) != 0)) { bCanServiceRequest = false; } // check for http specific verbs if (_protocol == Protocol.Http) { verb = (String)requestHeaders["__RequestVerb"]; if (!verb.Equals("POST") && !verb.Equals("M-POST")) { bCanServiceRequest = false; } } // either delegate or return an error message if we can't service the request if (!bCanServiceRequest) { // delegate to next sink if available if (_nextSink != null) { return(_nextSink.ProcessMessage(sinkStack, null, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream)); } else { // send back an error message if (_protocol == Protocol.Http) { // return a client bad request error responseHeaders = new TransportHeaders(); responseHeaders["__HttpStatusCode"] = "400"; responseHeaders["__HttpReasonPhrase"] = "Bad Request"; responseStream = null; responseMsg = null; return(ServerProcessing.Complete); } else { // The transport sink will catch this and do something here. throw new RemotingException( CoreChannel.GetResourceString("Remoting_Channels_InvalidRequestFormat")); } } } try { String objectUri = null; bool bIsCustomErrorEnabled = true; object oIsCustomErrorEnabled = requestHeaders["__CustomErrorsEnabled"]; if (oIsCustomErrorEnabled != null && oIsCustomErrorEnabled is bool) { bIsCustomErrorEnabled = (bool)oIsCustomErrorEnabled; } CallContext.SetData("__CustomErrorsEnabled", bIsCustomErrorEnabled); if (wkRequestHeaders != null) { objectUri = wkRequestHeaders.RequestUri; } else { objectUri = (String)requestHeaders[CommonTransportKeys.RequestUri]; } if (objectUri != lastUri && RemotingServices.GetServerTypeForUri(objectUri) == null) { throw new RemotingException( CoreChannel.GetResourceString("Remoting_ChnlSink_UriNotPublished")); } else { lastUri = objectUri; } PermissionSet currentPermissionSet = null; if (this.TypeFilterLevel != TypeFilterLevel.Full) { currentPermissionSet = new PermissionSet(PermissionState.None); currentPermissionSet.SetPermission(new SecurityPermission(SecurityPermissionFlag.SerializationFormatter)); } try { if (currentPermissionSet != null) { currentPermissionSet.PermitOnly(); } // Deserialize Request - Stream to IMessage requestMsg = CoreChannel.DeserializeBinaryRequestMessage(objectUri, requestStream, _strictBinding, this.TypeFilterLevel); } finally { if (currentPermissionSet != null) { CodeAccessPermission.RevertPermitOnly(); } } requestStream.Close(); if (requestMsg == null) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_DeserializeMessage")); } // Dispatch Call sinkStack.Push(this, null); processing = _nextSink.ProcessMessage(sinkStack, requestMsg, requestHeaders, null, out responseMsg, out responseHeaders, out responseStream); // make sure that responseStream is null if (responseStream != null) { throw new RemotingException( CoreChannel.GetResourceString("Remoting_ChnlSink_WantNullResponseStream")); } switch (processing) { case ServerProcessing.Complete: { if (responseMsg == null) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_DispatchMessage")); } sinkStack.Pop(this); SerializeResponse(sinkStack, responseMsg, ref responseHeaders, out responseStream); break; } // case ServerProcessing.Complete case ServerProcessing.OneWay: { sinkStack.Pop(this); break; } // case ServerProcessing.OneWay: case ServerProcessing.Async: { sinkStack.Store(this, null); break; } // case ServerProcessing.Async } // switch (processing) } catch (Exception e) { processing = ServerProcessing.Complete; responseMsg = new ReturnMessage(e, (IMethodCallMessage)(requestMsg == null?new ErrorMessage():requestMsg)); // CallContext.SetData("__ClientIsClr", true); responseStream = (MemoryStream)CoreChannel.SerializeBinaryMessage(responseMsg, _includeVersioning); CallContext.FreeNamedDataSlot("__ClientIsClr"); responseStream.Position = 0; responseHeaders = new TransportHeaders(); if (_protocol == Protocol.Http) { responseHeaders["Content-Type"] = CoreChannel.BinaryMimeType; } } finally{ CallContext.FreeNamedDataSlot("__CustomErrorsEnabled"); } return(processing); } // ProcessMessage
public BaseTransportHeaders ReadHeaders() { string str; string str2; string str3; string str5; bool bSendContinue = false; BaseTransportHeaders headers = new BaseTransportHeaders(); this.ReadFirstLine(out str, out str2, out str3); if (((str == null) || (str2 == null)) || (str3 == null)) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_UnableToReadFirstLine")); } if (str3.Equals("HTTP/1.1")) { this._version = System.Runtime.Remoting.Channels.Http.HttpVersion.V1_1; } else if (str3.Equals("HTTP/1.0")) { this._version = System.Runtime.Remoting.Channels.Http.HttpVersion.V1_0; } else { this._version = System.Runtime.Remoting.Channels.Http.HttpVersion.V1_1; } if (this._version == System.Runtime.Remoting.Channels.Http.HttpVersion.V1_1) { this._keepAlive = true; } else { this._keepAlive = false; } if (HttpChannelHelper.ParseURL(str2, out str5) == null) { str5 = str2; } headers["__RequestVerb"] = str; headers.RequestUri = str5; headers["__HttpVersion"] = str3; if ((this._version == System.Runtime.Remoting.Channels.Http.HttpVersion.V1_1) && (str.Equals("POST") || str.Equals("PUT"))) { bSendContinue = true; } base.ReadToEndOfHeaders(headers, out this._chunkedEncoding, out this._contentLength, ref this._keepAlive, ref bSendContinue); if (bSendContinue && (this._version != System.Runtime.Remoting.Channels.Http.HttpVersion.V1_0)) { this.SendContinue(); } headers["__IPAddress"] = ((IPEndPoint) base.NetSocket.RemoteEndPoint).Address; headers["__ConnectionId"] = this._connectionId; return headers; }
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
} // HttpHandlerTransportSink public void HandleRequest(HttpContext context) { HttpRequest httpRequest = context.Request; HttpResponse httpResponse = context.Response; // get headers BaseTransportHeaders requestHeaders = new BaseTransportHeaders(); requestHeaders["__RequestVerb"] = httpRequest.HttpMethod; requestHeaders["__CustomErrorsEnabled"] = HttpRemotingHandler.CustomErrorsEnabled(context); requestHeaders.RequestUri = (string)context.Items["__requestUri"]; NameValueCollection headers = httpRequest.Headers; String[] allKeys = headers.AllKeys; for (int httpKeyCount=0; httpKeyCount< allKeys.Length; httpKeyCount++) { String headerName = allKeys[httpKeyCount]; String headerValue = headers[headerName]; requestHeaders[headerName] = headerValue; } // add ip address to headers list requestHeaders.IPAddress = IPAddress.Parse(httpRequest.UserHostAddress); // get request stream Stream requestStream = httpRequest.InputStream; // process message ServerChannelSinkStack sinkStack = new ServerChannelSinkStack(); sinkStack.Push(this, null); IMessage responseMessage; ITransportHeaders responseHeaders; Stream responseStream; ServerProcessing processing = _nextSink.ProcessMessage(sinkStack, null, requestHeaders, requestStream, out responseMessage, out responseHeaders, out responseStream); // handle response switch (processing) { case ServerProcessing.Complete: { // Send the response. Call completed synchronously. SendResponse(httpResponse, 200, responseHeaders, responseStream); break; } // case ServerProcessing.Complete case ServerProcessing.OneWay: { // Just send back a 202 Accepted SendResponse(httpResponse, 202, responseHeaders, responseStream); break; } // case ServerProcessing.OneWay case ServerProcessing.Async: { // Async dispatching was cut from V.1. //sinkStack.StoreAndDispatch(this, streamManager); break; }// case ServerProcessing.Async } // switch (processing) } // HandleRequest