void ProcessRequest(ISmtpMessage smtpMessage, Smtp.Fields headers, Header[] msgHeaders, String contentType, String seqNum, MemoryStream stm, ref bool fIsOneWay) { IMessage outMsg = null; fIsOneWay = false; // Deserialize - Stream to IMessage IMessage inMsg = CoreChannel.DeserializeMessage(contentType, stm, true, null, msgHeaders); InternalRemotingServices.RemotingTrace("Deserialized message"); if (inMsg == null) { throw new Exception(CoreChannel.GetResourceString("Remoting_DeserializeMessage")); } // Set URI - BUGBUG: temp hack String url = ((IMethodMessage)inMsg).Uri; String objectURL = null; try { Parse(url, out objectURL); } catch (Exception) { objectURL = url; } inMsg.Properties["__Uri"] = objectURL; // Dispatch Call InternalRemotingServices.RemotingTrace("ChannelServices.SyncDispatchMessage - before"); outMsg = ChannelServices.SyncDispatchMessage(inMsg); InternalRemotingServices.RemotingTrace("ChannelServices.SyncDispatchMessage - after"); // We do not send a reply for one way messages. If the message // is not one way and we have a null return message then we // throw an exception if (null == outMsg) { MethodBase method = ((IMethodMessage)inMsg).MethodBase; fIsOneWay = RemotingServices.IsOneWay(method); if (!fIsOneWay) { throw new Exception(CoreChannel.GetResourceString("Remoting_DispatchMessage")); } } else { ReplyMessage(outMsg, smtpMessage, seqNum, headers); InternalRemotingServices.RemotingTrace("Reply sent"); } }
private void ProcessException(ISmtpMessage smtpMessage, Smtp.Fields headers, String contentType, String seqNum) { try { } catch (Exception) { // Fatal error .. ignore } }
// Generates a reply to an incoming Smtp message and sends it void ReplyMessage(IMessage replyMsg, ISmtpMessage smtpInMsg, String seqNum, Smtp.Fields headers) { MemoryStream stm = (MemoryStream)CoreChannel.SerializeMessage(m_mimeType, replyMsg); // reset stream to beginning stm.Position = 0; byte[] byteMessage = stm.ToArray(); int byteMessageLength = byteMessage.Length; String reply = System.Text.Encoding.ASCII.GetString(byteMessage, 0, byteMessage.Length); // Create a reply message MailMessage smtpOutMsg = new MailMessage(); // Fill in the headers PutHeaders(smtpOutMsg, smtpInMsg, (IMethodMessage)replyMsg, seqNum, reply.Length); // Set the body smtpOutMsg.Body = reply; // Send the message SmtpMail.Send(smtpOutMsg); }
String GetHeaders(ISmtpMessage smtpMessage, ref Smtp.Fields headers, ref String contentType, ref Header[] msgHeaders) { // Get the headers from the message object headers = smtpMessage.Fields; #if _DEBUG long count = headers.Count; InternalRemotingServices.RemotingTrace(" Count of fields " + count); for (long i = 0; i < count; i++) { //InternalRemotingServices.RemotingTrace(" Field " + i + " " + headers[i].Name + " " + headers[i].Value); } #endif // Get the content type string Field typeField = headers["urn:schemas:mailheader:contenttype"]; if (null == typeField) { throw new FormatException(CoreChannel.GetResourceString("Remoting_MissingContentType")); } contentType = (String)(typeField.Value); InternalRemotingServices.RemotingTrace("Content type " + typeField.Name + " " + contentType); // Extract the requested uri from the mail header Field uriField = headers["urn:schemas:mailheader:requesteduri"]; if (null == uriField) { throw new FormatException(CoreChannel.GetResourceString("Remoting_MissingRequestedURIHeader")); } String uriValue = (String)uriField.Value; if (null == uriValue) { throw new FormatException(CoreChannel.GetResourceString("Remoting_MissingRequestedURIHeader")); } // process SoapAction (extract the type and the name of the method to be invoked) Field actionField = headers["urn:schemas:mailheader:soapaction"]; if (null == actionField) { throw new FormatException(CoreChannel.GetResourceString("Remoting_SoapActionMissing")); } String actionValue = (String)actionField.Value; if (null == actionValue) { throw new FormatException(CoreChannel.GetResourceString("Remoting_SoapActionMissing")); } String typeName, methodName; if (!SoapServices.GetTypeAndMethodNameFromSoapAction(actionValue, out typeName, out methodName)) { // This means there are multiple methods for this soap action, so we will have to // settle for the type based off of the uri. Type type = RemotingServices.GetServerTypeForUri(uriValue); typeName = type.FullName + ", " + type.Module.Assembly.GetName().Name; } // BUGBUG: need code to verify soap action after the message has been deserialized. // this will probably be done once we have the new activation scenario working. msgHeaders = new Header[3]; msgHeaders[0] = new Header("__Uri", uriValue); msgHeaders[1] = new Header("__TypeName", typeName); msgHeaders[2] = new Header("__MethodName", methodName); // Extract the message sequence number field from the // mail header Field seqField = headers["urn:schemas:mailheader:soapmsgseqnum"]; if (null == seqField) { throw new FormatException(CoreChannel.GetResourceString("Remoting_MissingSoapMsgSeqNum")); } String seqValue = (String)(seqField.Value); InternalRemotingServices.RemotingTrace("Guid value " + seqValue); return(seqValue); }
// END: DICTIONARY IMPLEMENTION // ISmtpOnArrival // Receives incoming messages which can either be a request to dispatch // a call or a response to a call /// <include file='doc\SmtpChannel.uex' path='docs/doc[@for="SmtpChannel.OnArrival"]/*' /> public virtual void OnArrival(ISmtpMessage smtpMessage, ref CdoEventStatus EventStatus) { bool fIsOneWay = false; try { InternalRemotingServices.RemotingTrace("Reached OnArrival"); ISmtpOnArrival receiver = null; // Get the global receiver. If this instance is the global // receiver then proceed else delegate to it. if (IsReceiver(smtpMessage, ref receiver)) { // Check whether this message is a SOAP request message or a // SOAP response message String subject = smtpMessage.Subject; bool fRequest = false; // Proceed only if this is a SOAP request or response if (s_defaultSenderSubject.Equals(subject)) { fRequest = true; } else if (!s_defaultReceiverSubject.Equals(subject)) { throw new Exception("Invalid subject type " + subject); } // Extract the releavant mail headers String contentType = null; Smtp.Fields headers = null; Header[] msgHeaders = null; String seqNum = GetHeaders(smtpMessage, ref headers, ref contentType, ref msgHeaders); // Create a stream out of the body of the mail MemoryStream stm = new MemoryStream(Encoding.ASCII.GetBytes(smtpMessage.TextBody)); InternalRemotingServices.RemotingTrace("Created memory stream"); // Check whether this is a request or a response message if (fRequest) { // Dispatch this method and determine whether this // method is one way. ProcessRequest(smtpMessage, headers, msgHeaders, contentType, seqNum, stm, ref fIsOneWay); } else { ProcessResponse(smtpMessage, contentType, seqNum, stm); } } else { if (null != receiver) { // A message was addressed to us .. delegate to the // global receiver receiver.OnArrival(smtpMessage, ref EventStatus); } } InternalRemotingServices.RemotingTrace("Success!"); } catch (Exception e) { InternalRemotingServices.RemotingTrace("Reached an exception " + e.StackTrace); InternalRemotingServices.RemotingTrace("Exception message " + e.Message); if (!fIsOneWay) { //@TODO //ProcessException(smtpMessage, contentType, headers, seqNum); } } finally { EventStatus = CdoEventStatus.cdoRunNextSink; } }