/** * this method invites a new participant into the selected meeting. First, the participant * URL is grabbed from the Invite field and serialized. Then the serialized URL is passed to * the InviteAgent method in the local InfoAgent. The InviteAgent method first gets the signatures * of all of the existing participants, and then signs the message and sends it to the invitee * */ private void m_btnInvite_Click(object sender, System.EventArgs e) { //invite new participant to meeting: strSelectedMtg string strNewUrl = m_boxInvite.Text; StringBuilder strTest = new StringBuilder(); strTest.Append("we are inviting: "); strTest.Append(strNewUrl); string strNewUrlSerialized = Serializer.Serialize(strNewUrl); m_boxInvite.Text = strTest.ToString(); myctx.ClearParameters(); myctx.MethodName = "InviteAgent"; MeetingRequestMsg newMsg = new MeetingRequestMsg(); newMsg.Sender = cert.GetName(); newMsg.SenderUrl = strMyUrl; ArrayList lstParticipants = pDAO.GetParticipants(strSelectedMtg); foreach (MeetingParticipant mp in lstParticipants) { newMsg.m_lstParticipants.Add(mp); } newMsg.MeetingID = strSelectedMtg; newMsg.MeetingTopic = mDAO.GetMeetingTopic(strSelectedMtg); string strNewMsgSerialized = Serializer.Serialize(newMsg.ToXml()); myctx.AddParameter(strNewMsgSerialized); myctx.AddParameter(strNewUrlSerialized); object objectRes = null; try { objectRes = myexec.Execute(myctx); } catch (Exception exc) { string strBsg = exc.Message; return; } StringBuilder sbResult = new StringBuilder("Added "); sbResult.Append(strNewUrl).Append(" to meeting list"); m_boxInvite.Text = sbResult.ToString(); UpdateParticipantsList(); }
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; } } } }