using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using MySql.Data.MySqlClient;
using System; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using MySql.Data.MySqlClient;
namespace WcfMySqlService { // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“MysqlInfo”。 // 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 MysqlInfo.svc 或 MysqlInfo.svc.cs,然后开始调试。 public class MysqlInfo : IMysqlInfo { public void DoWork() { }
public DataSet GetDataSet(string tableName, string command) { string connector = $"server=localhost;port=3306;user=user;password=pwd;database={tableName}"; //using (MySqlConnection connection = new MySqlConnection(connector)) //{ try { MySqlConnection connection = new MySqlConnection(connector); connection.Open(); MySqlDataAdapter adapter = new MySqlDataAdapter(command, connection); DataSet set = new DataSet(); adapter.Fill(set, "item_info"); return set; } catch (Exception e) { Debug.Print(e.Message); return null; } //finally //{ // connection.Close(); //} //} }
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using WcfLinkRevit.ServiceReference1;
using WcfServiceLibrary;
using IService1 = WcfServiceLibrary.IService1;
namespace WcfLinkRevit
{
[Transaction(TransactionMode.Manual)]
public class Class1:IExternalCommand
{
private static readonly object _object = new object();
private IMysqlInfo m_server;
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
m_server = ChannelFactory<IMysqlInfo>.CreateChannel(new BasicHttpBinding(),
new EndpointAddress("http://120.27.124.206:8084/MysqlInfo.svc"));
UIDocument uidoc = commandData.Application.ActiveUIDocument;
var point = uidoc.Selection.PickPoint();
if (point != null)
{
var set = m_server.GetDataSet("recheck_model", "select * from projectlist");
StringBuilder builder = new StringBuilder("Revit -> Wcf -> Mysql");
for (int i = 0; i < set.Tables[0].Columns.Count; i++)
{
var name = set.Tables[0].Columns[i].ColumnName;
builder.AppendLine(name);
}
TaskDialog.Show("Wcf",builder.ToString());
//TaskDialog.Show("Wcf", m_server.Subtract(20.00D, 10.02D).ToString());
}
return Result.Succeeded;
}
}
}
1 2 3 4 5
重点是: ```csharp m_server = ChannelFactory<IMysqlInfo>.CreateChannel(new BasicHttpBinding(), new EndpointAddress("http://localhost:port/MysqlInfo.svc"));