public static ITransportHeaders ReceiveHeaders(Stream networkStream, byte[] buffer) { StreamRead (networkStream, buffer, 2); byte headerType = buffer [0]; TransportHeaders headers = new TransportHeaders (); while (headerType != 0) { string key; StreamRead (networkStream, buffer, 1); // byte 1 switch (headerType) { case 4: key = CommonTransportKeys.RequestUri; break; case 6: key = "Content-Type"; break; case 1: key = ReceiveString (networkStream, buffer); break; default: throw new NotSupportedException ("Unknown header code: " + headerType); } StreamRead (networkStream, buffer, 1); // byte 1 headers[key] = ReceiveString (networkStream, buffer); StreamRead (networkStream, buffer, 2); headerType = buffer [0]; } return headers; }
public void AsyncProcessResponse(IServerResponseChannelSinkStack sinkStack, object state, IMessage msg, ITransportHeaders headers, Stream stream) { ITransportHeaders responseHeaders = new TransportHeaders(); if (sinkStack != null) { stream = sinkStack.GetResponseStream(msg, responseHeaders); } if (stream == null) { stream = new MemoryStream(); } SoapMessageFormatter soapMsgFormatter = (SoapMessageFormatter)state; SoapMessage soapMessage = (SoapMessage)soapMsgFormatter.BuildSoapMessageFromMethodResponse((IMethodReturnMessage)msg, out responseHeaders); _soapCore.Serializer.Serialize(stream, soapMessage, null); if (stream is MemoryStream) { stream.Position = 0; } sinkStack.AsyncProcessResponse(msg, responseHeaders, stream); }
public void AsyncProcessRequest (IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders headers, Stream requestStream) { TcpConnection connection = null; bool isOneWay = RemotingServices.IsOneWay (((IMethodMessage)msg).MethodBase); try { if (headers == null) headers = new TransportHeaders(); headers [CommonTransportKeys.RequestUri] = ((IMethodMessage)msg).Uri; // Sends the stream using a connection from the pool // and creates a WorkItem that will wait for the // response of the server connection = TcpConnectionPool.GetConnection (_host, _port); TcpMessageIO.SendMessageStream (connection.Stream, requestStream, headers, connection.Buffer); connection.Stream.Flush (); if (!isOneWay) { sinkStack.Push (this, connection); ThreadPool.QueueUserWorkItem (new WaitCallback(ReadAsyncTcpMessage), sinkStack); } else connection.Release(); } catch { if (connection != null) connection.Release(); if (!isOneWay) throw; } }
public IPEndPoint Read(out ITransportHeaders headers, out Stream stream, out IPEndPoint remote) { // FIXME: 1) reliability 2) exceptions remote = new IPEndPoint(IPAddress.Loopback, 0); var buffer = UdpClient.Receive(ref remote); using (var ms = new MemoryStream(buffer)) using (var br = new BinaryReader(ms)) { var marker = br.ReadInt16(); if (marker != HeaderMarker && marker != DataMarker) { throw new InvalidDataException("Unexpected datagram format"); } // read transport headers headers = new TransportHeaders(); while (marker != DataMarker) { var name = br.ReadString(); var value = br.ReadString(); headers[name] = value; marker = br.ReadInt16(); } // get response stream var length = br.ReadInt32(); stream = new MemoryStream(buffer, (int)ms.Position, length); } return remote; }
public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink) { ITransportHeaders transportHeaders = new TransportHeaders(); transportHeaders[CommonTransportKeys.RequestUri] = ((IMethodCallMessage)msg).Uri; transportHeaders["Content-Type"] = "application/octet-stream"; Stream stream = _nextInChain.GetRequestStream(msg, transportHeaders); if (stream == null) { stream = new MemoryStream(); } _binaryCore.Serializer.Serialize(stream, msg, null); if (stream is MemoryStream) { stream.Position = 0; } ClientChannelSinkStack stack = new ClientChannelSinkStack(replySink); stack.Push(this, msg); _nextInChain.AsyncProcessRequest(stack, msg, transportHeaders, stream); // FIXME: No idea about how to implement IMessageCtrl return(null); }
public IMessage SyncProcessMessage(IMessage msg) { try { ITransportHeaders call_headers = new TransportHeaders(); call_headers[CommonTransportKeys.RequestUri] = ((IMethodCallMessage)msg).Uri; call_headers["Content-Type"] = "application/octet-stream"; Stream call_stream = _nextInChain.GetRequestStream(msg, call_headers); if (call_stream == null) { call_stream = new MemoryStream(); } // Serialize msg to the stream _binaryCore.Serializer.Serialize(call_stream, msg, null); if (call_stream is MemoryStream) { call_stream.Position = 0; } Stream response_stream; ITransportHeaders response_headers; _nextInChain.ProcessMessage(msg, call_headers, call_stream, out response_headers, out response_stream); // Deserialize response_stream return((IMessage)_binaryCore.Deserializer.DeserializeMethodResponse(response_stream, null, (IMethodCallMessage)msg)); } catch (Exception e) { return(new ReturnMessage(e, (IMethodCallMessage)msg)); } }
private static ITransportHeaders CollectResponseHeaders(HttpWebResponse response) { TransportHeaders headers = new TransportHeaders(); foreach (object obj2 in response.Headers) { string str = obj2.ToString(); headers[str] = response.Headers[str]; } return headers; }
public void AsyncProcessResponse (IServerResponseChannelSinkStack sinkStack, object state, IMessage message, ITransportHeaders headers, Stream stream) { ITransportHeaders responseHeaders = new TransportHeaders(); if (sinkStack != null) stream = sinkStack.GetResponseStream (message, responseHeaders); if (stream == null) stream = new MemoryStream(); _binaryCore.Serializer.Serialize (stream, message, null); if (stream is MemoryStream) stream.Position = 0; sinkStack.AsyncProcessResponse (message, responseHeaders, stream); }
public IMessageCtrl AsyncProcessMessage (IMessage msg, IMessageSink replySink) { Stream reqStream; FormatMessage (msg, out reqStream); TransportHeaders reqHeaders = new TransportHeaders(); ClientChannelSinkStack stack = new ClientChannelSinkStack (replySink); stack.Push (this, msg); _next.AsyncProcessRequest (stack, msg, reqHeaders, reqStream); return null; }
ServerProcessing IServerChannelSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream) { BinaryFormatter binaryFormatter = new BinaryFormatter(); binaryFormatter.Binder = new GenericsVTSSerializationBinder(); requestMsg = (IMessage)binaryFormatter.Deserialize(requestStream); requestMsg.Properties["__Uri"] = requestHeaders["__RequestUri"]; next.ProcessMessage(sinkStack, requestMsg, null, null, out responseMsg, out responseHeaders, out responseStream); responseHeaders = new TransportHeaders(); responseStream = new MemoryStream(); binaryFormatter.Serialize(responseStream, responseMsg); responseStream.Position = 0; return ServerProcessing.Complete; }
public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream) { IPAddress address = requestHeaders["__IPAddress"] as IPAddress; Console.Write("Process message from {0} ... ", address); if (!this.MatchIPAddress(address) ^ this.m_IsAccept) { TraceInfoEvent.Raise(string.Format("{0} is accepted by IPFilterChannelSink.", address)); Console.WriteLine("accepted"); return this.m_NextSink.ProcessMessage(sinkStack, requestMsg, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream); } TraceInfoEvent.Raise(string.Format("{0} is rejected by IPFilterChannelSink.", address)); responseHeaders = new TransportHeaders(); responseMsg = null; responseStream = null; return ServerProcessing.Complete; }
public void TransportHeadersSimpleTypesSerialization() { var th = new TransportHeaders(); th["Hehe"] = 123; th["Hoho"] = DateTime.Now; th["Haha"] = "localhost"; var ms = TransportHeaderWrapper.Serialize(th); Assert.IsNotNull(ms); ms.Position = 0; var th2 = TransportHeaderWrapper.Deserialize(ms); foreach (System.Collections.DictionaryEntry pair in th) { Assert.AreEqual(th[pair.Key], th2[pair.Key]); } }
public void TransportHeadersIPAddressSerialization() { var ip = IPAddress.Parse("192.168.254.104"); var th = new TransportHeaders(); th[CommonTransportKeys.IPAddress] = ip; th[CommonTransportKeys.RequestUri] = "localhost"; var ms = TransportHeaderWrapper.Serialize(th); Assert.IsNotNull(ms); ms.Position = 0; var th2 = TransportHeaderWrapper.Deserialize(ms); foreach (System.Collections.DictionaryEntry pair in th) { Assert.AreEqual(th[pair.Key], th2[pair.Key]); } }
// used by the client internal SoapMessage BuildSoapMessageFromMethodCall( IMethodCallMessage mcm, out ITransportHeaders requestHeaders) { requestHeaders = new TransportHeaders(); SoapMessage soapMsg = new SoapMessage(); GetInfoFromMethodCallMessage(mcm); // Format the SoapMessage that will be used to create the RPC soapMsg.MethodName = mcm.MethodName; //int count = mcm.ArgCount; ArrayList paramNames = new ArrayList(_methodCallParameters.Length); ArrayList paramTypes = new ArrayList(_methodCallParameters.Length); ArrayList paramValues = new ArrayList(_methodCallParameters.Length); // Add the function parameters to the SoapMessage class foreach (ParameterInfo paramInfo in _methodCallParameters) { if (!(paramInfo.IsOut && paramInfo.ParameterType.IsByRef)) { Type t = paramInfo.ParameterType; if (t.IsByRef) { t = t.GetElementType(); } paramNames.Add(paramInfo.Name); paramTypes.Add(t); paramValues.Add(mcm.Args[paramInfo.Position]); } } soapMsg.ParamNames = (string[])paramNames.ToArray(typeof(string)); soapMsg.ParamTypes = (Type[])paramTypes.ToArray(typeof(Type)); soapMsg.ParamValues = (object[])paramValues.ToArray(typeof(object)); soapMsg.XmlNameSpace = SoapServices.GetXmlNamespaceForMethodCall(_methodCallInfo); soapMsg.Headers = BuildMessageHeaders(mcm); // Format the transport headers requestHeaders["Content-Type"] = "text/xml; charset=\"utf-8\""; requestHeaders["SOAPAction"] = "\"" + SoapServices.GetSoapActionFromMethodBase(_methodCallInfo) + "\""; requestHeaders[CommonTransportKeys.RequestUri] = mcm.Uri; return(soapMsg); }
private void Authenticate(IMessage msg) { System.IO.Stream requestStream = new System.IO.MemoryStream(); TransportHeaders requestHeaders = new System.Runtime.Remoting.Channels.TransportHeaders(); requestHeaders[CommonHeaders.EncryptionType] = EncryptionType.HandshakeRequest; requestHeaders[CommonHeaders.AuthenticationType] = AuthenticationType.ChallengeRequest; requestHeaders[CommonHeaders.PublicKey] = crypto.PublicKey; requestHeaders["Content-Type"] = "text/xml; charset=utf-8"; //requestHeaders["Content-Type"] = "application/octet-stream"; System.IO.Stream responseStream; ITransportHeaders responseHeaders; nextSink.ProcessMessage(msg, requestHeaders, requestStream, out responseHeaders, out responseStream); string xmlKey = responseHeaders[CommonHeaders.PublicKey].ToString(); crypto.DeriveKey(xmlKey); }
public void AsyncProcessResponse(IServerResponseChannelSinkStack sinkStack, object state, IMessage msg, ITransportHeaders headers, Stream stream) { ITransportHeaders responseHeaders = new TransportHeaders(); if (sinkStack != null) { stream = sinkStack.GetResponseStream(msg, responseHeaders); } if (stream == null) { stream = new MemoryStream(); } _binaryCore.Serializer.Serialize(stream, msg, null); if (stream is MemoryStream) { stream.Position = 0; } sinkStack.AsyncProcessResponse(msg, responseHeaders, stream); }
internal void InternalProcessMessage (Ice.Endpoint replyEp, Stream msgStream, Ice.MessageType mtype) { // at this point, the ice header has been read, but nothing higher. // we don't know very much about this message; we pass it up // to (presumably) the formatter for further evaluation TransportHeaders headers = new TransportHeaders(); headers ["__iceMessageType"] = mtype; headers ["__iceEndpoint"] = replyEp; IMessage respMessage; ITransportHeaders respHeaders; Stream respStream; ServerProcessing res = _next.ProcessMessage (null, null, headers, msgStream, out respMessage, out respHeaders, out respStream); switch (res) { case ServerProcessing.Complete: if (!(respHeaders != null && respHeaders["__iceNoReply"] != null && ((bool) respHeaders["__iceNoReply"]))) { lock (replyEp.Stream) { MemoryStream ms = respStream as MemoryStream; ms.WriteTo (replyEp.Stream); } } break; case ServerProcessing.Async: throw new NotImplementedException(); case ServerProcessing.OneWay: // do nothing break; } }
// used by the client internal SoapMessage BuildSoapMessageFromMethodCall( IMethodCallMessage mcm, out ITransportHeaders requestHeaders) { requestHeaders = new TransportHeaders(); SoapMessage soapMsg = new SoapMessage(); GetInfoFromMethodCallMessage(mcm); // Format the SoapMessage that will be used to create the RPC soapMsg.MethodName = mcm.MethodName; //int count = mcm.ArgCount; ArrayList paramNames = new ArrayList(_methodCallParameters.Length); ArrayList paramTypes = new ArrayList(_methodCallParameters.Length); ArrayList paramValues = new ArrayList(_methodCallParameters.Length); // Add the function parameters to the SoapMessage class foreach(ParameterInfo paramInfo in _methodCallParameters) { if (!(paramInfo.IsOut && paramInfo.ParameterType.IsByRef)) { Type t = paramInfo.ParameterType; if (t.IsByRef) t = t.GetElementType (); paramNames.Add(paramInfo.Name); paramTypes.Add(t); paramValues.Add(mcm.Args[paramInfo.Position]); } } soapMsg.ParamNames = (string[]) paramNames.ToArray(typeof(string)); soapMsg.ParamTypes = (Type[]) paramTypes.ToArray(typeof(Type)); soapMsg.ParamValues = (object[]) paramValues.ToArray(typeof(object)); soapMsg.XmlNameSpace = SoapServices.GetXmlNamespaceForMethodCall(_methodCallInfo); soapMsg.Headers = BuildMessageHeaders (mcm); // Format the transport headers requestHeaders["Content-Type"] = "text/xml; charset=\"utf-8\""; requestHeaders["SOAPAction"] = "\""+ SoapServices.GetSoapActionFromMethodBase(_methodCallInfo)+"\""; requestHeaders[CommonTransportKeys.RequestUri] = mcm.Uri; return soapMsg; }
// used by the server internal object BuildSoapMessageFromMethodResponse(IMethodReturnMessage mrm, out ITransportHeaders responseHeaders) { responseHeaders = new TransportHeaders(); if (mrm.Exception == null) { // *normal* function return SoapMessage soapMessage = new SoapMessage(); // fill the transport headers responseHeaders["Content-Type"] = "text/xml; charset=\"utf-8\""; // build the SoapMessage ArrayList paramNames = new ArrayList(); ArrayList paramValues = new ArrayList(); ArrayList paramTypes = new ArrayList(); soapMessage.MethodName = mrm.MethodName + "Response"; Type retType = ((MethodInfo)mrm.MethodBase).ReturnType; if (retType != typeof(void)) { paramNames.Add("return"); paramValues.Add(mrm.ReturnValue); if (mrm.ReturnValue != null) { paramTypes.Add(mrm.ReturnValue.GetType()); } else { paramTypes.Add(retType); } } for (int i = 0; i < mrm.OutArgCount; i++) { paramNames.Add(mrm.GetOutArgName(i)); paramValues.Add(mrm.GetOutArg(i)); if (mrm.GetOutArg(i) != null) { paramTypes.Add(mrm.GetOutArg(i).GetType()); } } soapMessage.ParamNames = (string[])paramNames.ToArray(typeof(string)); soapMessage.ParamValues = (object[])paramValues.ToArray(typeof(object)); soapMessage.ParamTypes = (Type[])paramTypes.ToArray(typeof(Type)); soapMessage.XmlNameSpace = _xmlNamespace; soapMessage.Headers = BuildMessageHeaders(mrm); return(soapMessage); } else { // an Exception was thrown while executing the function responseHeaders["__HttpStatusCode"] = "500"; responseHeaders["__HttpReasonPhrase"] = "Bad Request"; // fill the transport headers responseHeaders["Content-Type"] = "text/xml; charset=\"utf-8\""; ServerFault serverFault = CreateServerFault(mrm.Exception); return(new SoapFault("Server", String.Format(" **** {0} - {1}", mrm.Exception.GetType().ToString(), mrm.Exception.Message), null, serverFault)); } }
public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream) { // Check whether the request was already processed by another // formatter sink and pass the request to the next sink if so. if (requestMsg != null) { return(next_sink.ProcessMessage(sinkStack, requestMsg, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream)); } // Check whether the request is suitable for this formatter // and pass the request to the next sink if not. // Note that a null content-type is handled as suitable, // otherwise no other sink will be able to handle the request. string contentType = requestHeaders["Content-Type"] as string; if (contentType != null && contentType != "application/octet-stream") { try { return(next_sink.ProcessMessage(sinkStack, requestMsg, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream)); } catch { // Let this formatter handle the exception. } } sinkStack.Push(this, null); ServerProcessing res; try { string url = (string)requestHeaders[CommonTransportKeys.RequestUri]; string uri; receiver.Parse(url, out uri); if (uri == null) { uri = url; } MethodCallHeaderHandler mhh = new MethodCallHeaderHandler(uri); requestMsg = (IMessage)_binaryCore.Deserializer.Deserialize(requestStream, new HeaderHandler(mhh.HandleHeaders)); res = next_sink.ProcessMessage(sinkStack, requestMsg, requestHeaders, null, out responseMsg, out responseHeaders, out responseStream); } catch (Exception ex) { responseMsg = new ReturnMessage(ex, (IMethodCallMessage)requestMsg); res = ServerProcessing.Complete; responseHeaders = null; responseStream = null; } if (res == ServerProcessing.Complete) { for (int n = 0; n < 3; n++) { responseStream = null; responseHeaders = new TransportHeaders(); if (sinkStack != null) { responseStream = sinkStack.GetResponseStream(responseMsg, responseHeaders); } if (responseStream == null) { responseStream = new MemoryStream(); } try { _binaryCore.Serializer.Serialize(responseStream, responseMsg); break; } catch (Exception ex) { if (n == 2) { throw ex; } else { responseMsg = new ReturnMessage(ex, (IMethodCallMessage)requestMsg); } } } if (responseStream is MemoryStream) { responseStream.Position = 0; } sinkStack.Pop(this); } return(res); }
public void SendResponse(Stream httpContentStream, string statusCode, string reasonPhrase, ITransportHeaders headers) { if (this._responseStream != null) { this._responseStream.Close(); if (this._responseStream != httpContentStream) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_WrongResponseStream")); } this._responseStream = null; } else { if (headers == null) { headers = new TransportHeaders(); } string serverHeader = (string) headers["Server"]; if (serverHeader != null) { serverHeader = HttpServerTransportSink.ServerHeader + ", " + serverHeader; } else { serverHeader = HttpServerTransportSink.ServerHeader; } headers["Server"] = serverHeader; if (!this.AllowChunkedResponse && (httpContentStream != null)) { headers["Content-Length"] = httpContentStream.Length.ToString(CultureInfo.InvariantCulture); } else if (httpContentStream == null) { headers["Content-Length"] = "0"; } this.GetResponseStream(statusCode, reasonPhrase, headers); if (httpContentStream != null) { StreamHelper.CopyStream(httpContentStream, this._responseStream); this._responseStream.Close(); httpContentStream.Close(); } this._responseStream = null; } }
public void AsyncProcessResponse (IServerResponseChannelSinkStack sinkStack, object state, IMessage msg, ITransportHeaders headers, Stream stream) { ITransportHeaders responseHeaders = new TransportHeaders(); if(sinkStack != null) stream = sinkStack.GetResponseStream(msg, responseHeaders); if(stream == null) stream = new MemoryStream(); SoapMessageFormatter soapMsgFormatter = (SoapMessageFormatter)state; SoapMessage soapMessage = (SoapMessage) soapMsgFormatter.BuildSoapMessageFromMethodResponse((IMethodReturnMessage)msg, out responseHeaders); _soapCore.Serializer.Serialize(stream, soapMessage, null); if(stream is MemoryStream) stream.Position = 0; sinkStack.AsyncProcessResponse (msg, responseHeaders, stream); }
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, StringComparison.Ordinal) != 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; } } bool bIsCustomErrorEnabled = true; object oIsCustomErrorEnabled = requestHeaders["__CustomErrorsEnabled"]; if (oIsCustomErrorEnabled != null && oIsCustomErrorEnabled is bool){ bIsCustomErrorEnabled = (bool)oIsCustomErrorEnabled; } CallContext.SetData("__CustomErrorsEnabled", bIsCustomErrorEnabled); String soapActionToVerify; Header[] h = GetChannelHeaders(requestHeaders, out soapActionToVerify); 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.DeserializeSoapRequestMessage(requestStream, h, _strictBinding, this.TypeFilterLevel); } finally { if (currentPermissionSet != null) CodeAccessPermission.RevertPermitOnly(); } 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( CultureInfo.CurrentCulture, 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; } } finally{ CallContext.FreeNamedDataSlot("__CustomErrorsEnabled"); } return processing; } // ProcessMessage
public ServerProcessing ProcessMessage (IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream) { responseMsg = null; responseStream = null; responseHeaders = null; string verb = requestHeaders [CommonTransportKeys.RequestVerb] as string; string uri = (string) requestHeaders [CommonTransportKeys.RequestUri]; if (verb == "GET" && uri.EndsWith ("?wsdl")) { try { uri = uri.Substring (0, uri.Length - 5); Type type = RemotingServices.GetServerTypeForUri (uri); string url = _channel.GetUrlsForUri (uri)[0]; ServiceType st = new ServiceType (type, url); responseStream = new MemoryStream (); MetaData.ConvertTypesToSchemaToStream (new ServiceType[] {st}, SdlType.Wsdl, responseStream); responseStream.Position = 0; responseMsg = null; responseHeaders = new TransportHeaders (); responseHeaders [CommonTransportKeys.ContentType] = "text/xml"; } catch (Exception ex) { responseHeaders = new TransportHeaders (); responseHeaders [CommonTransportKeys.HttpStatusCode] = "400"; responseStream = new MemoryStream (Encoding.UTF8.GetBytes (ex.ToString ())); } return ServerProcessing.Complete; } else return _next.ProcessMessage (sinkStack, requestMsg, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream); }
void IClientChannelSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, System.IO.Stream requestStream, out ITransportHeaders responseHeaders, out System.IO.Stream responseStream) { lock (authHelper) { if (!authHelper.HaveNonce) { System.Runtime.Remoting.Channels.TransportHeaders authHeaders = new TransportHeaders(); System.IO.MemoryStream authStream = new System.IO.MemoryStream(); authHelper.SetRequest(authHeaders); ITransportHeaders authedHeaders; System.IO.Stream authedStream; nextSink.ProcessMessage(msg, authHeaders, authStream, out authedHeaders, out authedStream); //System.IO.MemoryStream memStream = BaseHelper.ToMemoryStream(authedStream); //char[] chars = new System.Text.UTF8Encoding().GetChars(memStream.ToArray(), 0, (int)memStream.Length); authHelper.SetNonce(authedHeaders); } } authHelper.Authenticate(requestHeaders, ref requestStream); nextSink.ProcessMessage(msg, requestHeaders, requestStream, out responseHeaders, out responseStream); }
// private methods // void SerializeMessage( IMethodCallMessage mcm, ref ITransportHeaders headers, ref Stream stream) { ITransportHeaders reqHeaders = new TransportHeaders(); reqHeaders["__Uri"] = mcm.Uri; reqHeaders["Content-Type"] = "text/xml; charset=\"utf-8\""; reqHeaders["__RequestVerb"] = "POST"; MethodInfo mi = (MethodInfo)mcm.MethodBase; string methodName = GetRpcMethodName(mi); XmlRpcRequest xmlRpcReq = new XmlRpcRequest(methodName, mcm.InArgs); // TODO: possibly call GetRequestStream from next sink in chain? // TODO: SoapClientFormatter sink uses ChunkedStream - check why? Stream stm = new MemoryStream(); var serializer = new XmlRpcRequestSerializer(); serializer.SerializeRequest(stm, xmlRpcReq); stm.Position = 0; headers = reqHeaders; stream = stm; }
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); } SdlType sdlType; if (!ShouldIntercept(requestHeaders, out sdlType)) return _nextSink.ProcessMessage(sinkStack, null, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream); // generate sdl and return it responseHeaders = new TransportHeaders(); GenerateSdl(sdlType, sinkStack, requestHeaders, responseHeaders, out responseStream); responseMsg = null; return ServerProcessing.Complete; } // ProcessMessage
} // 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
private static bool SendRequestForChannel (RequestArguments reqArg, IDictionary HeaderFields, IDictionary CustomHeaders, byte[] buffer) { TransportHeaders THeaders = new TransportHeaders(); Stream stream = new MemoryStream(buffer); if(stream.Position !=0) stream.Seek(0,SeekOrigin.Begin); THeaders[CommonTransportKeys.RequestUri] = FixURI((string)HeaderFields["request-url"]); THeaders[CommonTransportKeys.ContentType]= HeaderFields["content-type"]; THeaders[CommonTransportKeys.RequestVerb]= HeaderFields["method"]; THeaders[CommonTransportKeys.HttpVersion] = HeaderFields["http-version"]; THeaders[CommonTransportKeys.UserAgent] = HeaderFields["user-agent"]; THeaders[CommonTransportKeys.Host] = HeaderFields["host"]; THeaders[CommonTransportKeys.SoapAction] = HeaderFields["SOAPAction"]; THeaders[CommonTransportKeys.IPAddress] = reqArg.ClientAddress; THeaders[CommonTransportKeys.ConnectionId] = reqArg.Id; foreach(DictionaryEntry DictEntry in CustomHeaders) { THeaders[DictEntry.Key.ToString()] = DictEntry.Value.ToString(); } reqArg.Sink.ServiceRequest (reqArg, stream, THeaders); return true; }
} // 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
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); }
public IMessage SyncProcessMessage (IMessage msg) { try { ITransportHeaders call_headers = new TransportHeaders(); call_headers[CommonTransportKeys.RequestUri] = ((IMethodCallMessage)msg).Uri; call_headers["Content-Type"] = "application/octet-stream"; Stream call_stream = _nextInChain.GetRequestStream(msg, call_headers); if (call_stream == null) call_stream = new MemoryStream (); // Serialize msg to the stream _binaryCore.Serializer.Serialize (call_stream, msg, null); if (call_stream is MemoryStream) call_stream.Position = 0; Stream response_stream; ITransportHeaders response_headers; _nextInChain.ProcessMessage (msg, call_headers, call_stream, out response_headers, out response_stream); // Deserialize response_stream return (IMessage) _binaryCore.Deserializer.DeserializeMethodResponse (response_stream, null, (IMethodCallMessage)msg); } catch (Exception e) { return new ReturnMessage (e, (IMethodCallMessage)msg); } }
} // ReceiveAndProcess private static ITransportHeaders CollectResponseHeaders(HttpWebResponse response) { TransportHeaders responseHeaders = new TransportHeaders(); foreach (Object key in response.Headers) { String keyString = key.ToString(); responseHeaders[keyString] = response.Headers[keyString]; } return responseHeaders; } // CollectResponseHeaders
} // 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
public IMessage SyncProcessMessage (IMessage msg) { IMethodCallMessage call = (IMethodCallMessage)msg; // we catch all exceptions to return them as message try { // create a new header TransportHeaders req_headers = new TransportHeaders (); //fixme: set some header values Stream out_stream = new MemoryStream (); // serialize msg to the stream format.SerializeRequest (out_stream, msg); // call the next sink ITransportHeaders resp_headers; Stream resp_stream; nextInChain.ProcessMessage (msg, req_headers, out_stream, out resp_headers, out resp_stream); // deserialize resp_stream IMessage result = (IMessage) format.DeserializeResponse (resp_stream, call); // it's save to close the stream now resp_stream.Close (); return result; } catch (Exception e) { return new ReturnMessage (e, call); } }
private void SerializeRequestMessage(IMethodCallMessage methodCallMessage , out ITransportHeaders requestHeaders , out Stream requestStream) { requestHeaders = new TransportHeaders(); requestHeaders["RequestMethod"] = methodCallMessage.MethodName; requestHeaders["Format"] = "json"; var shouldRewindStream = false; requestStream = this._nextChannelSink.GetRequestStream(methodCallMessage, requestHeaders); if (requestStream == null) { requestStream = new MemoryStream(); shouldRewindStream = true; } byte[] data = _serializer.SerializeMethodCall(new MethodCall() { Uri = methodCallMessage.Uri, MethodName = methodCallMessage.MethodName, TypeName = methodCallMessage.TypeName, MethodSignature = (Type[])methodCallMessage.MethodSignature, Args = methodCallMessage.Args }); requestStream.Write(data, 0, data.Length); if (shouldRewindStream) requestStream.Position = 0; }
public IMessageCtrl AsyncProcessMessage (IMessage msg, IMessageSink replySink) { ITransportHeaders transportHeaders = new TransportHeaders(); transportHeaders[CommonTransportKeys.RequestUri] = ((IMethodCallMessage)msg).Uri; transportHeaders["Content-Type"] = "application/octet-stream"; Stream stream = _nextInChain.GetRequestStream(msg, transportHeaders); if (stream == null) stream = new MemoryStream (); _binaryCore.Serializer.Serialize (stream, msg, null); if (stream is MemoryStream) stream.Position = 0; ClientChannelSinkStack stack = new ClientChannelSinkStack(replySink); stack.Push (this, msg); _nextInChain.AsyncProcessRequest (stack, msg, transportHeaders, stream); // FIXME: No idea about how to implement IMessageCtrl return null; }
/// <summary> /// Erzeugt den gemeinsamen Schlüssel und bereitet dessen Übertragung zum Client vor. /// </summary> /// <param name="transactID">Sicherheitstransaktionskennung</param> /// <param name="requestHeaders">Anfrage-Header vom Client</param> /// <param name="responseMsg">Antwortnachricht</param> /// <param name="responseHeaders">Antwort-Header</param> /// <param name="responseStream">Antwort-Datenstrom</param> /// <returns>Status</returns> private ServerProcessing MakeSharedKey(Guid transactID, ITransportHeaders requestHeaders, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream) { // Gemeinsamer Schlüssel und Inizialisierungsvektor SymmetricAlgorithm symmetricProvider = CryptoTools.CreateSymmetricCryptoProvider(_algorithm); // Clientverbindungsdaten erzeugen ClientConnectionData connectionData = new ClientConnectionData(transactID, symmetricProvider); lock (_connections.SyncRoot) { // Clientverbindungsdaten unter der angegebenen Sicherheitstransaktionskennung speichern _connections[transactID.ToString()] = connectionData; } // RSA Kryptografieanbieter erzeugen RSACryptoServiceProvider rsaProvider = new RSACryptoServiceProvider(); // Öffentlichen Schlüssel (vom Client) aus den Anfrage-Headern lesen string publicKey = (string)requestHeaders[CommonHeaderNames.PUBLIC_KEY]; // Wenn kein öffentlicher Schlüssel gefunden wurde ... if (string.IsNullOrEmpty(publicKey)) throw new CryptoRemotingException(LanguageResource.CryptoRemotingException_PublicKeyNotFound); // Öffentlichen Schlüssel in den Kryptografieanbieter laden rsaProvider.FromXmlString(publicKey); // Gemeinsamen Schlüssel und dessen Inizialisierungsfaktor verschlüsseln byte[] encryptedKey = rsaProvider.Encrypt(symmetricProvider.Key, _oaep); byte[] encryptedIV = rsaProvider.Encrypt(symmetricProvider.IV, _oaep); // Antwort-Header zusammenstellen responseHeaders = new TransportHeaders(); responseHeaders[CommonHeaderNames.SECURE_TRANSACTION_STATE] = ((int)SecureTransactionStage.SendingSharedKey).ToString(); responseHeaders[CommonHeaderNames.SHARED_KEY] = Convert.ToBase64String(encryptedKey); responseHeaders[CommonHeaderNames.SHARED_IV] = Convert.ToBase64String(encryptedIV); // Es wird keine Antwortnachricht benötigt responseMsg = null; responseStream = new MemoryStream(); // Vollständige Verarbeitung zurückmelden return ServerProcessing.Complete; }
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
/// <summary> /// Erzeugt eine leere Antwortnachricht. /// </summary> /// <param name="transactionStage">Art des aktuellen Transaktionsschritts</param> /// <param name="responseMsg">Antwort-Nachricht</param> /// <param name="responseHeaders">Antwort-Header</param> /// <param name="responseStream">Antwort-Datenstrom</param> /// <returns>Verarbeitungsstatus</returns> private ServerProcessing SendEmptyToClient(SecureTransactionStage transactionStage, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream) { // Inizialisieren responseMsg = null; responseStream = new MemoryStream(); responseHeaders = new TransportHeaders(); // Aktuellen Transaktionsschritt als Antwort-Header schreiben responseHeaders[CommonHeaderNames.SECURE_TRANSACTION_STATE] = ((int)transactionStage).ToString(); // Volständige Verarbeitung zurückmelden return ServerProcessing.Complete; }
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")); } // Transparent proxy IMessages are allowed conditionally by AppSettings if (RemotingServices.IsTransparentProxy(requestMsg) && !AppSettings.AllowTransparentProxyMessage) { // Null request to prevent calling transparent proxy methods in catch below. // Fwlink is provided to explain why it is not supported. Inner exceptions propagate back to sender. requestMsg = null; throw new RemotingException(CoreChannel.GetResourceString("Remoting_DeserializeMessage"), new NotSupportedException(AppSettings.AllowTransparentProxyMessageFwLink)); } // 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
// used by the server internal object BuildSoapMessageFromMethodResponse(IMethodReturnMessage mrm, out ITransportHeaders responseHeaders) { responseHeaders = new TransportHeaders(); if(mrm.Exception == null) { // *normal* function return SoapMessage soapMessage = new SoapMessage(); // fill the transport headers responseHeaders["Content-Type"] = "text/xml; charset=\"utf-8\""; // build the SoapMessage ArrayList paramNames = new ArrayList(); ArrayList paramValues = new ArrayList(); ArrayList paramTypes = new ArrayList(); soapMessage.MethodName = mrm.MethodName+"Response"; Type retType = ((MethodInfo)mrm.MethodBase).ReturnType; if(retType != typeof(void)) { paramNames.Add("return"); paramValues.Add(mrm.ReturnValue); if (mrm.ReturnValue != null) paramTypes.Add(mrm.ReturnValue.GetType()); else paramTypes.Add(retType); } for(int i = 0; i < mrm.OutArgCount; i++){ paramNames.Add(mrm.GetOutArgName(i)); paramValues.Add(mrm.GetOutArg(i)); if(mrm.GetOutArg(i) != null) paramTypes.Add(mrm.GetOutArg(i).GetType()); } soapMessage.ParamNames = (string[]) paramNames.ToArray(typeof(string)); soapMessage.ParamValues = (object[]) paramValues.ToArray(typeof(object)); soapMessage.ParamTypes = (Type[]) paramTypes.ToArray(typeof(Type)); soapMessage.XmlNameSpace = _xmlNamespace; soapMessage.Headers = BuildMessageHeaders (mrm); return soapMessage; } else { // an Exception was thrown while executing the function responseHeaders["__HttpStatusCode"] = "500"; responseHeaders["__HttpReasonPhrase"] = "Bad Request"; // fill the transport headers responseHeaders["Content-Type"] = "text/xml; charset=\"utf-8\""; ServerFault serverFault = CreateServerFault(mrm.Exception); return new SoapFault("Server", String.Format(" **** {0} - {1}", mrm.Exception.GetType().ToString(), mrm.Exception.Message), null, serverFault); } }