1
我尝试通过WCF服务创建一个插入操作。这是我所做的。首先,我会告诉你我的项目结构如何通过MYSQL通过WCF服务插入操作?
每个文件的解释:
IServiceClient.cs
包含服务合同的组
[ServiceContract]
public interface IServiceClient
{
[OperationContract]
void InsertMaster();
}
Service.cs
包含数据合同
[DataContract]
public class Service
{
[DataMember]
public string Id;
[DataMember]
public string Submitter;
[DataMember]
public string Comments;
[DataMember]
public DateTime TimeSubmitted;
}
ServiceClient.cs
含有,如插入业务逻辑来操作MySQL
public void InsertMaster()
{
string query = "INSERT INTO movies (id, submitter, comments, time) VALUES(id, submitter, comments, time)";
//open connection
connection.Open();
//create command and assign the query and connection from the constructor
MySqlCommand cmd = new MySqlCommand(query, connection);
//Execute command
cmd.ExecuteNonQuery();
//close connection
connection.Close();
}
,我的问题是,如何将数据合约场传递给ServiceClient.cs这样我就可以写一些MySQL查询?该“查询字符串”只是我的演示,我想从合同数据
给我的第二个问题是如何将数据合同区加载到WCF测试客户端将该值插入?我需要测试它即将工作或不是我用它在我的客户端项目
公共无效InsertMaster(服务数据)和OperationContract的空隙InsertMaster(服务数据)是相同的; –
为什么不让你的数据合约接受服务类型,在ServiceClient类中实现它。然后,当你运行你的WCF测试客户端,您应该能够将其数据填写服务类别,并提交,如果不是你可以随时请求XML从XML选项卡底部的复制,然后使用的程序等PostMan在Chrome中填写您的数据并将其发布到服务中。 – Bearcat9425