static void Main(string[] args)
        {
            // Dynamic proxy generation...

            // Create a new proxy generation request
            ProxyGenRequest req = new ProxyGenRequest();

            // Set the location of the assembly to be generated
            // leave empty ("") for current directory
            req.ProxyPath = "";
            // Set the name of the assembly (dll) that will be generated
            req.ServiceName = "WeatherSvc";
            // Set the url of the web service's WSDL file
            req.WsdlUrl = "http://www.xmethods.net/sd/2001/TemperatureService.wsdl";

            // Create a WSE mutator, generated proxies will expose the RequestContext
            // and ResponseContext properties
            ProxyPolicyMutator mutator = new ProxyPolicyMutator();

            // Set the name of the proxy class generated
            mutator.ProxyName = req.ServiceName;

            // Create the proxy generator
            ProxyGen pxyGen = new ProxyGen();

            // Set the proxy generator's mutator
            pxyGen.Mutator = mutator;
            // Generate the proxy
            string strAssembly = pxyGen.GenerateAssembly(req);

            // Dynamic invocation...

            // Set the parameter...note it MUST be in xml form
            string strZipcode = "<string>10025</string>";

            // Create an execution context
            ExecContext ctx = new ExecContext();

            // Set the fully qualified name of the web service proxy
            // (FullQname = <Namespace>.<classname>"
            ctx.ServiceName = req.Namespace + "." + req.ServiceName;
            // Set the name of the assembly where the proxy class "lives"
            ctx.Assembly = strAssembly;
            // Set the name of the method to dynamically invoke
            ctx.MethodName = "getTemp";
            // Add any parameters
            ctx.AddParameter(strZipcode);

            // Create an Executor
            Executor exec = new Executor();
            // Execute using the context
            object objRes = exec.Execute(ctx);
        }
        /**
         * much like the method to send resources, this method is used to recall resources
         * that are being shared.  The resources to be recalled are the resources that are
         * selected in the GUI.  First, it creates a ResourceContextMsg and an Executor to
         * the local InfoAgent.  It then calls the RecallMyResources method on the local InfoAgent.
         * */
        private void m_btnRecall_Click(object sender, System.EventArgs e)
        {
            ResourceCtxMsg rctx = new ResourceCtxMsg();

            rctx.MeetingID = strSelectedMtg;
            rctx.Sender    = strMyName;
            rctx.Type      = enuContextMsgType.ResourceRecalled;
            rctx.SenderUrl = strMyUrl;

            foreach (string strSel in m_boxResources.SelectedItems)
            {
                rctx.AddResourceID(strSel);
            }

            string strResponse = Serializer.Serialize(rctx.ToXml());

            ProxyGenRequest pxyreq = new ProxyGenRequest();

            pxyreq.ProxyPath   = "";
            pxyreq.ServiceName = "InfoAgent";
            pxyreq.WsdlUrl     = strMyUrl;

            ProxyPolicyMutator mymutator = new ProxyPolicyMutator();

            mymutator.ProxyName = pxyreq.ServiceName;

            // Ensure the name of the file generated is unique
            string strMySuffix = "";
            int    nMyCode     = Guid.NewGuid().GetHashCode();

            if (nMyCode < 0)
            {
                nMyCode = nMyCode * -1;
            }
            strMySuffix        = nMyCode.ToString();
            pxyreq.ServiceName = pxyreq.ServiceName + "_" + strMySuffix;

            ProxyGen myPxyGen = new ProxyGen();

            myPxyGen.Mutator = mymutator;

            string strMyAssembly = "";

            try
            {
                strMyAssembly = myPxyGen.GenerateAssembly(pxyreq);
            }
            catch (Exception excep)
            {
                string strString = excep.Message;
            }

            ExecContext myctx = new ExecContext();

            myctx.ServiceName = pxyreq.Namespace + "." + mymutator.ProxyName;
            myctx.Assembly    = strMyAssembly;

            Executor myexec = new Executor();

            myexec.Settings.ExpectSignedResponse = false;
            myexec.Settings.SigningCertificate   = cert;

            myctx.MethodName = "RecallMyResources";
            myctx.AddParameter(strResponse);

            object objectRes = null;

            try
            {
                objectRes = myexec.Execute(myctx);
            }
            catch (Exception exc)
            {
                string strBsg = exc.Message;
                return;
            }
        }
        /**
         * this method sends a resource
         * first, it checks to see if any new resource request messages have arrived
         * into the ContextMessageDAO.  If so, then for each resource request, it
         * sends a resource response to the sender.  For each selected resource in the GUI,
         * it adds the resource to the resource response.  Next, it creates an Executor / Executor
         * Context to communicate with the InfoAgent that sent the message.  It then calls the Recommend
         * method on that InfoAgent that requested the resource, passing the selected resources (serialized)
         * in the parameter
         * */
        private void m_btnSend_Click(object sender, System.EventArgs e)
        {
            //first i check for resource request messages
            ArrayList   lstNew = cmDAO.GetNewReceivedContextMessages();
            IEnumerator it     = lstNew.GetEnumerator();

            while (it.MoveNext())
            {
                if (it.Current is RecommendationRequestCtxMsg)
                {
                    RecommendationRequestCtxMsg  recReq     = (RecommendationRequestCtxMsg)it.Current;
                    RecommendationResponseCtxMsg respctxmsg = new RecommendationResponseCtxMsg(recReq);

                    ResourceMsg msg = new ResourceMsg();
                    msg.MeetingID = recReq.MeetingID;
                    msg.Sender    = respctxmsg.Sender;
                    msg.SenderUrl = respctxmsg.SenderUrl;

                    foreach (string strSel in m_boxResources.SelectedItems)
                    {
                        foreach (Resource r in lstResources)
                        {
                            if (r.ID == strSel)
                            {
                                msg.m_lstResources.Add(r);
                            }
                        }
                    }

                    respctxmsg.ResourceMessage = msg;

                    string strResponse     = Serializer.Serialize(respctxmsg.ToXml());
                    string strInfoagenturl = recReq.SenderUrl;

                    ProxyGenRequest pxyreq = new ProxyGenRequest();
                    pxyreq.ProxyPath   = "";
                    pxyreq.ServiceName = "InfoAgent";
                    pxyreq.WsdlUrl     = strInfoagenturl;

                    ProxyPolicyMutator mymutator = new ProxyPolicyMutator();
                    mymutator.ProxyName = pxyreq.ServiceName;

                    // Ensure the name of the file generated is unique
                    string strMySuffix = "";
                    int    nMyCode     = Guid.NewGuid().GetHashCode();
                    if (nMyCode < 0)
                    {
                        nMyCode = nMyCode * -1;
                    }
                    strMySuffix        = nMyCode.ToString();
                    pxyreq.ServiceName = pxyreq.ServiceName + "_" + strMySuffix;

                    ProxyGen myPxyGen = new ProxyGen();
                    myPxyGen.Mutator = mymutator;

                    string strMyAssembly = "";
                    try
                    {
                        strMyAssembly = myPxyGen.GenerateAssembly(pxyreq);
                    }
                    catch (Exception excep)
                    {
                        string strString = excep.Message;
                    }

                    ExecContext myctx = new ExecContext();
                    myctx.ServiceName = pxyreq.Namespace + "." + mymutator.ProxyName;
                    myctx.Assembly    = strMyAssembly;

                    Executor myexec = new Executor();
                    myexec.Settings.ExpectSignedResponse = false;
                    myexec.Settings.SigningCertificate   = cert;

                    myctx.MethodName = "Recommend";
                    myctx.AddParameter(strResponse);

                    object objectRes = null;

                    try
                    {
                        objectRes = myexec.Execute(myctx);
                    }
                    catch (Exception exc)
                    {
                        string strBsg = exc.Message;
                        return;
                    }
                }
            }
        }
Beispiel #4
0
        /**
         * this constructor does the following:
         * 1.  read in the X.509 certificate from the machine store
         * 2.  get the localhost IP address
         * 3.  create an executor / executor context for the local InfoAgent
         * 4.  create the DAO objects to access contents in the database
         * 5.  update the existing meetings with all meetings in the database
         * */
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            store = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore);
            store.OpenRead();

            strMyId = "CN=Omar";
            certCol = store.FindCertificateBySubjectName(strMyId);

            cert      = (X509Certificate)certCol[0];
            certToken = new X509SecurityToken(cert);

            me      = new MeetingParticipant();
            me.Name = cert.GetName();
            me.Role = enuMeetingParticipantRole.Organizer;

            strFileLocation = "TotalRecall/InfoAgent.asmx?wsdl";
            string      strHost = Dns.GetHostName();
            IPHostEntry entry   = Dns.Resolve(strHost);
            string      strIP   = "";

            if (entry.AddressList.Length > 0)
            {
                IPAddress addr = new IPAddress(entry.AddressList[0].Address);
                strIP = addr.ToString();
            }
            else
            {
                m_boxInvite.Text = "ERROR getting host IP";
                return;
            }
            StringBuilder strbldUrl = new StringBuilder(strIP);

            strbldUrl.Append(strFileLocation);
            me.Location = strbldUrl.ToString();


            //create my infoagent
            strMyUrl = "http://localhost/TotalRecall/InfoAgent.asmx?wsdl";

            ProxyGenRequest pxyreq = new ProxyGenRequest();

            pxyreq.ProxyPath   = "";
            pxyreq.ServiceName = "InfoAgent";
            pxyreq.WsdlUrl     = strMyUrl;

            ProxyPolicyMutator mymutator = new ProxyPolicyMutator();

            mymutator.ProxyName = pxyreq.ServiceName;

            // Ensure the name of the file generated is unique
            string strMySuffix = "";
            int    nMyCode     = Guid.NewGuid().GetHashCode();

            if (nMyCode < 0)
            {
                nMyCode = nMyCode * -1;
            }
            strMySuffix        = nMyCode.ToString();
            pxyreq.ServiceName = pxyreq.ServiceName + "_" + strMySuffix;

            ProxyGen myPxyGen = new ProxyGen();

            myPxyGen.Mutator = mymutator;

            string strMyAssembly = "";

            try
            {
                strMyAssembly = myPxyGen.GenerateAssembly(pxyreq);
            }
            catch (Exception excep)
            {
                string strString = excep.Message;
            }

            myctx             = new ExecContext();
            myctx.ServiceName = pxyreq.Namespace + "." + mymutator.ProxyName;
            myctx.Assembly    = strMyAssembly;


            myexec = new Executor();
            myexec.Settings.ExpectSignedResponse = true;
            myexec.Settings.SigningCertificate   = cert;

            dbConnect = "DSN=TotalRecall;UID=TotalRecallUser;PWD=totalrecall;DATABASE=TotalRecall";

            mDAO = new MeetingDAO(dbConnect);
            pDAO = new ParticipantDAO(dbConnect);
            rDAO = new ResourceDAO(dbConnect);
            cDAO = new ContactDAO(dbConnect);

            strSelectedMtg = "";
            ArrayList lstMtgs = mDAO.GetMeetingIDs(enuMeetingState.Active);

            foreach (string s in lstMtgs)
            {
                m_boxMtgs.Items.Add(s);
            }
        }