// Simple scenario to show how an agent could execute a WS described using // DAML private object DemoExecuteService(DamlProcess process, DAMLParameter zipcode) { object objRes = null; // Ensure zipcode.Type matches to System.String in .NET world if (zipcode.Type == enuDAMLType.stringType && process.Inputs[0].Range.IndexOf("#string") != -1) { DynamicPxy.WeatherRetriever wr = new DynamicPxy.WeatherRetriever(); Type PxyType = wr.GetType(); // Even though we pass zipcode.data which is an object it is // dynamically cast to string MethodInfo mInfo = PxyType.GetMethod(process.Name); if (mInfo != null) { objRes = mInfo.Invoke(wr, new object[] { zipcode.Data }); } } else { MessageBox.Show("Input type mismatch on process execute"); } return(objRes); }
private void btnExecDemo_Click(object sender, System.EventArgs e) { if (!this.tvwExecDetails.Visible) { return; } this.tvwExecDetails.Nodes.Clear(); LoadProcessData(m_demoProcess, ref tvwExecDetails); DAMLParameter zipcode = new DAMLParameter(); zipcode.Type = enuDAMLType.stringType; zipcode.Data = "10025"; TreeNode resultsNode = new TreeNode("Results"); object objRes = null; // Do execute objRes = DemoExecuteService(m_demoProcess, zipcode); string strRetVal = "No results available"; // Add results if (objRes != null) { // Serialize to string // Get returned type Type returnType = objRes.GetType(); // Create XmlSerializer XmlSerializer ser = new XmlSerializer(returnType); // Create a memory stream MemoryStream ms = new MemoryStream(); // Serialize to stream ms ser.Serialize(ms, objRes); // Goto start of stream ms.Seek(0, System.IO.SeekOrigin.Begin); // Create a stream reader TextReader reader = new StreamReader(ms); // Read entire stream, this is our return value strRetVal = reader.ReadToEnd(); resultsNode.Nodes.Add(strRetVal); } else { resultsNode.Nodes.Add(strRetVal); } this.rtbResults.Text = strRetVal; this.tvwExecDetails.Nodes.Add(resultsNode); }