private string _processSoap(SoapMessage message)
        {
            StringBuilder sb = new StringBuilder(8192);
            string        result;

            try
            {
                sb.Append(message.MethodInfo.Name);
                for (int i = 0; i < message.MethodInfo.Parameters.Length; i++)
                {
                    sb.Append("[" + message.MethodInfo.Parameters[i].Name + "=");
                    if (message.MethodInfo.Parameters[i].ParameterType.FullName.StartsWith("System.") && !message.MethodInfo.Parameters[i].IsOut)
                    {
                        sb.Append((message.GetInParameterValue(i) != null) ? message.GetInParameterValue(i) : "null");
                    }
                    else
                    {
                        sb.Append(message.MethodInfo.Parameters[i].ParameterType.FullName);
                    }
                    sb.Append("]");
                }
                result = sb.ToString();
            }
            catch
            {
                result = null;
            }
            finally
            {
            }
            return(result);
        }
示例#2
0
    // Write the contents of the outgoing SOAP message to the log file.
    public void WriteOutputBeforeSerialize(SoapMessage message)
    {
        FileStream myFileStream =
            new FileStream(filename, FileMode.Append, FileAccess.Write);
        StreamWriter myStreamWriter = new StreamWriter(myFileStream);

        myStreamWriter.WriteLine("================================== Request at "
                                 + DateTime.Now);
// <Snippet7>
        myStreamWriter.WriteLine("The method that has been invoked is: ");
        myStreamWriter.WriteLine("\t" + message.MethodInfo);
// </Snippet7>
// <Snippet2>
        myStreamWriter.WriteLine(
            "The contents of the SOAPAction HTTP header is:");
        myStreamWriter.WriteLine("\t" + message.Action);
// </Snippet2>
// <Snippet3>
        myStreamWriter.WriteLine("The contents of HTTP Content-type header is:");
        myStreamWriter.WriteLine("\t" + message.ContentType);
// </Snippet3>
// <Snippet4>
        if (message.OneWay)
        {
            myStreamWriter.WriteLine(
                "The method invoked on the client shall not wait"
                + " till the server finishes");
        }
        else
        {
            myStreamWriter.WriteLine(
                "The method invoked on the client shall wait"
                + " till the server finishes");
        }
// </Snippet4>
// <Snippet5>
        myStreamWriter.WriteLine(
            "The site where the XML Web service is available is:");
        myStreamWriter.WriteLine("\t" + message.Url);
// </Snippet5>
// <Snippet6>
        myStreamWriter.WriteLine("The values of the in parameters are:");
        myStreamWriter.WriteLine("Value of first in parameter: {0}",
                                 message.GetInParameterValue(0));
        myStreamWriter.WriteLine("Value of second in parameter: {0}",
                                 message.GetInParameterValue(1));
// </Snippet6>
        myStreamWriter.WriteLine();
        myStreamWriter.Flush();
        myStreamWriter.Close();
        myFileStream.Close();
    }
示例#3
0
    // Write the contents of the outgoing SOAP message to the log file.
    public void WriteOutputBeforeSerialize(SoapMessage myMessage)
    {
        FileStream   myFileStream   = new FileStream(myFileName, FileMode.Append, FileAccess.Write);
        StreamWriter myStreamWriter = new StreamWriter(myFileStream);

        myStreamWriter.WriteLine("================================== Request at "
                                 + DateTime.Now);

        myStreamWriter.WriteLine("The method that has been invoked is : ");
        myStreamWriter.WriteLine("\t" + myMessage.MethodInfo);

        myStreamWriter.WriteLine("The contents of the SOAPAction HTTP header is :");
        myStreamWriter.WriteLine("\t" + myMessage.Action);

        myStreamWriter.WriteLine("The contents of HTTP Content-type header is :");
        myStreamWriter.WriteLine("\t" + myMessage.ContentType);

        if (myMessage.OneWay)
        {
            myStreamWriter.WriteLine("The method invoked on the client shall not wait"
                                     + " till the server finishes");
        }
        else
        {
            myStreamWriter.WriteLine("The method invoked on the client shall wait"
                                     + " till the server finishes");
        }

        myStreamWriter.WriteLine("The site where the web service is available is : ");
        myStreamWriter.WriteLine("\t" + myMessage.Url);

        myStreamWriter.WriteLine("The values of the in parameters are :");
        myStreamWriter.WriteLine("Value of first in parameter : {0}",
                                 myMessage.GetInParameterValue(0));
        myStreamWriter.WriteLine("Value of second in parameter : {0}",
                                 myMessage.GetInParameterValue(1));

        myStreamWriter.Write("Number of headers for the current request: ");
        myStreamWriter.WriteLine(myMessage.Headers.Count);
        if (myMessage.Exception != null)
        {
            myStreamWriter.WriteLine("Exception1 : " + myMessage.Exception.Message);
        }

        myStreamWriter.WriteLine();
        myStreamWriter.Flush();
        myStreamWriter.Close();
        myFileStream.Close();
    }
示例#4
0
 private void SaveCallInfo(SoapMessage message)
 {
     _methodName = message.MethodInfo.Name;
     // the parameter value is converted to a string for logging, 
     // but this may not be suitable for all applications.
     ParameterInfo[] parminfo = message.MethodInfo.InParameters;
     _parameters = parminfo.Select((t, i) => new KeyValuePair<string, String>(
             t.Name, Convert.ToString(message.GetInParameterValue(i)))).ToList();
 }
示例#5
0
// <Snippet1>
    // Write the contents of the outgoing SOAP message to the log file.
    public void WriteOutputBeforeSerialize(SoapMessage myMessage)
    {
        FileStream myFileStream =
            new FileStream(myFileName, FileMode.Append, FileAccess.Write);
        StreamWriter myStreamWriter = new StreamWriter(myFileStream);

        myStreamWriter.WriteLine(
            "================================== Request at " + DateTime.Now);

        myStreamWriter.WriteLine("The values of the in parameters are:");
        myStreamWriter.WriteLine("Value of first in parameter: {0}",
                                 myMessage.GetInParameterValue(0));
        myStreamWriter.WriteLine("Value of second in parameter: {0}",
                                 myMessage.GetInParameterValue(1));

        myStreamWriter.Write("Number of headers for the current request: ");
        myStreamWriter.WriteLine(myMessage.Headers.Count);

        myStreamWriter.WriteLine();
        myStreamWriter.Flush();
        myStreamWriter.Close();
        myFileStream.Close();
    }
        public void WriteOutput(SoapMessage message)
        {
            FileStream   fs           = new FileStream(filename, FileMode.Append, FileAccess.Write);
            StreamWriter streamWriter = new StreamWriter(fs);

            if (message is SoapClientMessage)
            {
                if (message.MethodInfo.InParameters.Length > 0)
                {
                    object obj = message.GetInParameterValue(0);
                    System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(obj.GetType());
                    xs.Serialize(streamWriter, obj);
                }
            }

            streamWriter.Flush();
            streamWriter.Close();
        }
示例#7
0
 /// <summary>
 /// This method logs soap method calls.
 /// </summary>
 /// <param name="Msg"></param>
 private void Log(SoapMessage Msg)
 {
     CallLog = this.LogHeader(Msg) + "(";
     if (Msg.Stage == SoapMessageStage.AfterDeserialize)
     {
         LogicalMethodInfo M = Msg.MethodInfo;
         int n = 0;
         foreach (ParameterInfo P in M.InParameters)
         {
             CallLog += LogInParameter(P, Msg.GetInParameterValue(n), LogSoapComplexTypes) + ",";
             n++;
         }
         if (CallLog.Substring(CallLog.Length - 1, 1) == ",")
         {
             CallLog = CallLog.Substring(0, CallLog.Length - 1);
         }
     }
     CallLog += ")";
 }
        private static object[] GetRequestArgs(SoapMessage message)
        {
            var keepGoing = true;
            var i         = 0;
            var objects   = new List <object>();

            while (keepGoing)
            {
                try
                {
                    objects.Add(message.GetInParameterValue(i));
                    i++;
                }
                catch
                {
                    keepGoing = false;
                }
            }
            return(objects.ToArray());
        }
示例#9
0
    public void WriteInput(SoapMessage message)
    {
        FileStream   fs = new FileStream(filename, FileMode.Append, FileAccess.Write);
        StreamWriter w  = new StreamWriter(fs);

        if (message is SoapServerMessage)
        {
            w.WriteLine("METHOD CALL at " + DateTime.Now);
            int ipc = message.MethodInfo.InParameters.Length;
            if (ipc > 0)
            {
                w.WriteLine("  Parameters:");
            }
            for (int n = 0; n < ipc; n++)
            {
                w.WriteLine("     " + message.GetInParameterValue(n));
            }
        }

        w.Flush();
        w.Close();
    }
示例#10
0
        public override void ProcessMessage(SoapMessage message)
        {
            try
            {
                switch (message.Stage)
                {
                case SoapMessageStage.BeforeDeserialize:
                    //
                    // Check to see if the server has been manually stopped.
                    //
                    if (0 == Config.GetInt("Run", 1))
                    {
                        DispositionReport.ThrowFinal(new UDDIException(ErrorType.E_busy, "UDDI_ERROR_BUSY_SERVICENOTAVAILABLE"));

                        //
                        // DispositionReport.ThrowFinal will close the HTTP stream so there is no point going on in this method
                        //
                        return;
                    }

                    try
                    {
                        //
                        // Validate against the UDDI schemas
                        //
                        SchemaCollection.Validate(oldStream);
                    }
                    catch (Exception e)
                    {
                        DispositionReport.ThrowFinal(new UDDIException(ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_SCHEMAVALIDATIONFAILED", e.Message));

                        //
                        // DispositionReport.ThrowFinal will close the HTTP stream so there is no point going on in this method
                        //
                        return;
                    }

                    //
                    // Make sure we only have 1 UDDI request in the SOAP body.  This method will also set the versionMajor
                    // member.
                    //
                    CheckForSingleRequest(oldStream);

                    //
                    // If this is a v1 message, we'll first map it to the v2
                    // namespace so that it can be processed by the new
                    // library.
                    //
                    if (1 == Context.ApiVersionMajor || 2 == Context.ApiVersionMajor)
                    {
                        TextReader reader = new StreamReader(oldStream);
                        TextWriter writer = new StreamWriter(newStream, new System.Text.UTF8Encoding(false));
                        string     xml    = reader.ReadToEnd();

                        if (1 == Context.ApiVersionMajor)
                        {
                            xml = xml.Replace("=\"urn:uddi-org:api\"", "=\"urn:uddi-org:api_v2\"");
                            xml = xml.Replace("='urn:uddi-org:api'", "=\"urn:uddi-org:api_v2\"");
                        }
                        writer.Write(xml);
                        writer.Flush();

                        newStream.Position = 0;
                    }

                    break;

                case SoapMessageStage.AfterDeserialize:
                    //
                    // After the message is deserialized is the earliest place where we
                    // have access to our SOAP headers.
                    //
                    CheckSOAPHeaders(message);

                    //
                    // Now that the message has been deserialized, make
                    // sure that the generic and xmlns attributes agree.
                    //
                    IMessage obj = message.GetInParameterValue(0) as IMessage;
                    if (null != obj)
                    {
                        //
                        // We only need to do this if the deserialized object supports IMessage
                        //
                        string expected = Context.ApiVersionMajor + ".0";
                        string actual   = obj.Generic.Trim();

                        if (expected != actual)
                        {
                            throw new UDDIException(ErrorType.E_unrecognizedVersion, "UDDI_ERROR_UNKNOWNVERSION_GENERICNAMESPACEMISMATCH");
                        }
                    }

                    break;

                case SoapMessageStage.BeforeSerialize:
                    break;

                case SoapMessageStage.AfterSerialize:

                    //
                    // There may have been exceptions thrown during serialization.
                    //
                    if (null != message.Exception &&
                        (null == message.Exception.Detail ||
                         0 == message.Exception.Detail.ChildNodes.Count))
                    {
                        DispositionReport.ThrowFinal(new UDDIException(ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_FAILEDDESERIALIZATION"));

                        //
                        // DispositionReport.ThrowFinal will close the HTTP stream so there is no point going on in this method
                        //
                        return;
                    }

                    //
                    // If the original request was v1, then we'll need to
                    // remap the output to use the v1 namespace.
                    //
                    if (1 == Context.ApiVersionMajor || 2 == Context.ApiVersionMajor)
                    {
                        newStream.Position = 0;

                        TextReader reader = new StreamReader(newStream);
                        TextWriter writer = new StreamWriter(oldStream, new System.Text.UTF8Encoding(false));

                        string xml = reader.ReadToEnd();

                        //
                        // We don't have to use the same 'loose' replacement as we did on the incoming request
                        // because our response will be serialized such that the default namespace is our UDDI
                        // namespace.
                        //

                        if (1 == Context.ApiVersionMajor)
                        {
                            xml = xml.Replace("xmlns=\"urn:uddi-org:api_v2\"", "xmlns=\"urn:uddi-org:api\"");
                            xml = xml.Replace("generic=\"2.0\"", "generic=\"1.0\"");
                        }
                        writer.Write(xml);
                        writer.Flush();
                    }

                    break;

                default:
                    throw new UDDIException(ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_UNKNOWNEXTSTAGE");
                }
            }
            catch (Exception e)
            {
                DispositionReport.Throw(e);
            }
        }
示例#11
0
        //
        // What follows is the logic for selection of the authentication algorithm
        // Enjoy boys and girls
        //
        //	    Bit 3 - Anonymous User
        //	     Bit 2 - UDDI Authentication Mode
        //	      Bit 1 - Windows Authentication Mode
        //		   Bit 0 - Ticket Present
        //         |
        //		   |		Authentication Module Used
        //		0000		X
        //		0001		X
        //		0010		Windows
        //		0011		Exception ( UDDI authentication turned off )
        //		0100		UDDI ( will fail authentication due to invalid credentials )
        //		0101		UDDI
        //		0110		Windows
        //		0111		UDDI
        //		1000		X
        //		1001		X
        //		1010		Exception UDDI authentication turned off
        //		1011		Exception ""
        //		1100		UDDI ( will fail authentication due to invalid credentials )
        //		1101		UDDI
        //		1110		UDDI ( will fail authentication due to invalid credentials )
        //		1111		UDDI
        //
        //
        // Reduction Work
        //
        // A - Anonymous User
        // B - UDDI Authentication Mode
        // C - Windows Authentication Mode
        // D - Ticket Present
        //
        // Key
        //		e - throw exception invalid configuration
        //		x - invalid state
        //      w - windows authentication
        //		u - uddi authentication
        //
        //		CD
        //	AB	00 01 11 10
        //	00  x  x  e  w
        //	01  u  u  u  w
        //	11  u  u  u  u
        //	10  x  x  e  e
        //
        // if( !A && C && !D )
        //		w - windows authentication
        // else if( B )
        //		u - uddi authentication
        // else
        //		throw exception
        //

        private void Authenticate(SoapMessage message)
        {
            Debug.Enter();

            IAuthenticateable authenticate = (IAuthenticateable)message.GetInParameterValue(0);
            //WindowsIdentity identity = (WindowsIdentity)HttpContext.Current.User.Identity;
            IIdentity identity = HttpContext.Current.User.Identity;
            int       mode     = Config.GetInt("Security.AuthenticationMode", (int)AuthenticationMode.Both);

            if (mode == (int)AuthenticationMode.Passport)
            {
                if (identity is PassportIdentity)
                {
                    string ticket = authenticate.AuthInfo.Trim();

                    //
                    // Authentication the user using the attached passport ticket
                    //
                    PassportAuthenticator pa = new PassportAuthenticator();
                    pa.Authenticate(ticket, Config.GetInt("Security.TimeOut", 60));
                }
                else
                {
                    throw new UDDIException(ErrorType.E_fatalError,
                                            "UDDI_ERROR_FATALERROR_PASSPORTBADCONFIG");
                }
                Debug.Write(SeverityType.Info, CategoryType.Soap, "Authenticated user: using Passport based authentication Identity is " + identity.Name);
            }
            else if (!((WindowsIdentity)identity).IsAnonymous &&
                     ((mode & (int)AuthenticationMode.Windows) != 0) &&
                     Utility.StringEmpty(authenticate.AuthInfo))
            {
                /* 0X10 Case */
                //
                // Authenticate the user using the currently impersonated credentials
                //
                WindowsAuthenticator wa = new WindowsAuthenticator();
                wa.Authenticate(authenticate.AuthInfo, Config.GetInt("Security.TimeOut", 60));

                Debug.Write(SeverityType.Info, CategoryType.Soap, "Authenticated user: using Windows based authentication Identity is " + identity.Name);
            }
            else if ((mode & (int)AuthenticationMode.Uddi) != 0)
            {
                /* X1XX Case for leftovers */
                //
                // If windows authentication is turned off or the
                Debug.Write(SeverityType.Info, CategoryType.Soap, "Anonymous user: using UDDI authentication");

                //
                // Authenticate the user using the authToken
                //
                UDDIAuthenticator ua = new UDDIAuthenticator();
                ua.Authenticate(authenticate.AuthInfo, Config.GetInt("Security.TimeOut", 60));
            }
            else
            {
                //
                // Throw exception for the rest
                //
                throw new UDDIException(UDDI.ErrorType.E_unsupported,
                                        "UDDI_ERROR_UNSUPPORTED_BADAUTHENTICATIONCONFIG");
            }

            //
            // Check to make sure the authenticated user has publisher credentials
            //
            Debug.Verify(Context.User.IsPublisher,
                         "UDDI_ERROR_FATALERROR_USERNOPUBLISHERCRED",
                         UDDI.ErrorType.E_fatalError,
                         Context.User.ID);

            //
            // The server can be configured for automatic registration of publishers with credentials
            //
            if (!Context.User.IsRegistered)
            {
                if (1 == Config.GetInt("Security.AutoRegister", 0))
                {
                    //
                    // Mark the user as verified.
                    //
                    Context.User.TrackPassport = false;
                    Context.User.Verified      = true;

                    Context.User.Register();
                }
                else
                {
                    throw new UDDIException(UDDI.ErrorType.E_unknownUser,
                                            "UDDI_ERROR_UNKNOWNUSER_NOTREGISTERED");
                }
            }

            Context.User.Login();
#if DEBUG
            Debug.Write(SeverityType.Info, CategoryType.Soap, "Windows Identity is " + WindowsIdentity.GetCurrent().Name);
            Debug.Write(SeverityType.Info, CategoryType.Soap, "Thread Identity is " + System.Threading.Thread.CurrentPrincipal.Identity.Name);
            Debug.Write(SeverityType.Info, CategoryType.Soap, "HttpContext Identity is " + identity.Name);
            Debug.Write(SeverityType.Info, CategoryType.Soap, "IsAdministrator = " + Context.User.IsAdministrator);
            Debug.Write(SeverityType.Info, CategoryType.Soap, "IsCoordinator = " + Context.User.IsCoordinator);
            Debug.Write(SeverityType.Info, CategoryType.Soap, "IsPublisher = " + Context.User.IsPublisher);
            Debug.Write(SeverityType.Info, CategoryType.Soap, "IsUser = " + Context.User.IsUser);
#endif
            Debug.Leave();
        }
示例#12
0
	public void WriteInput(SoapMessage message)
	{
		FileStream fs = new FileStream(filename, FileMode.Append, FileAccess.Write);
		StreamWriter w = new StreamWriter(fs);

		if (message is SoapServerMessage)
		{
			w.WriteLine("METHOD CALL at " + DateTime.Now);
			int ipc = message.MethodInfo.InParameters.Length;
			if (ipc > 0) w.WriteLine ("  Parameters:");
			for (int n=0; n<ipc; n++)
				w.WriteLine ("     " + message.GetInParameterValue (n));
		}

		w.Flush();
		w.Close();
	}
示例#13
0
        /// <summary>
        /// Collects the the set of DimeAttachment objects to send in the message.
        /// For referenced attachments these are collected from the parameter list or return value.
        /// For unreferenced attachments these are collected from the IDimeAttachmentContainter
        /// collections. The SOAP envelope and attachments are written into the network stream
        /// in the AfterSerialize method.
        /// If an exception has been thrown, the soap message containing the exception is
        /// not encapsulated.
        /// </summary>
        private void BeforeSerialize(SoapMessage message)
        {
            if (dimeDir == DimeDir.Response)
            {
                return;                 //because not on request
            }
            if (message.Exception == null)
            {
                id = message.Action;
                message.ContentType = DimeContentType;
                outputAttachments   = new ArrayList();

                if (message.GetType() != typeof(SoapClientMessage))
                {
                    throw new Exception("DIME library not for server side processing");

                    /*
                     * // check for unreferenced attachments in the container
                     * IDimeAttachmentContainer container = ((SoapServerMessage)message).Server as IDimeAttachmentContainer;
                     * if (container != null)
                     *      outputAttachments.AddRange(container.ResponseAttachments);
                     * else
                     * {
                     *      // check for referenced attachments in out parameter list
                     *      ParameterInfo[] parameters = message.MethodInfo.OutParameters;
                     *      for (int i = 0; i < parameters.Length; i++)
                     *      {
                     *              // Note, using the as operator to test the type since out params have a unique type
                     *              object outValue = message.GetOutParameterValue(i);
                     *              if ((outValue as DimeAttachment) != null || (outValue as DimeAttachment[]) != null)
                     *                      AddAttachmentValue(outValue.GetType(), outValue);
                     *      }
                     *
                     *      // check for referenced attachment in return value
                     *      Type returnType = message.MethodInfo.ReturnType;
                     *      if (returnType == typeof(DimeAttachment) || returnType == typeof(DimeAttachment[]))
                     *              AddAttachmentValue(returnType, message.GetReturnValue());
                     * }
                     */
                }
                else                 //client side
                {
                    // check for unreferenced attachments in the container
                    IDimeAttachmentContainer container = ((SoapClientMessage)message).Client as IDimeAttachmentContainer;
                    if (container != null)
                    {
                        outputAttachments.AddRange(container.RequestAttachments);
                    }
                    else
                    {
                        // check for referenced attachments in the parameter list
                        ParameterInfo[] parameters = message.MethodInfo.InParameters;
                        for (int i = 0; i < parameters.Length; i++)
                        {
                            Type type = parameters[i].ParameterType;
                            if (type == typeof(DimeAttachment) || type == typeof(DimeAttachment[]))
                            {
                                AddAttachmentValue(type, message.GetInParameterValue(i));
                            }
                        }
                    }
                }
            }
        }