Reputation: 163
This is my project:
IWCFService.cs
[ServiceContract]
public interface IWCFService
{
[OperationContract]
void SetValue(string value);
[OperationContract]
bool SaveToDatabase();
}
WCFService.cs
public class WCFService : IWCFService
{
public void SetValue(string value);
{
//Code insert value
}
public bool SaveToDatabase);
{
//Code save values to database
}
}
WindowsServiceHost.cs
public partial class WindowsServiceHost : ServiceBase
{
private ServiceHost _host;
public WindowsServiceHost()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
_host = new ServiceHost(typeof (WCFService.WCFService));
_host.Open();
}
protected override void OnStop()
{
_host.Close();
}
}
frmClient.cs
public partial class frmClient : Form
{
private WCFServiceClient _client = new WCFServiceClient();
public frmClient()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
_client.SetValue(39);
MessageBox.Show("Done!");
}
private void button2_Click(object sender, EventArgs e)
{
_client.SetValue(50);
MessageBox.Show("Done!");
}
private void button3_Click(object sender, EventArgs e)
{
_client.SaveToDatabase();
MessageBox.Show("Done!");
}
}
Where can I put shared memory (to set value from many clients)? (in WCF Service or Windows Service)
Can I call SaveToDatabase() from Windows Service? (calling automatically after 5 seconds)
Thanks!
Upvotes: 0
Views: 303
Reputation: 3797
Web service method call should be considered as complete operation, so if you need to store passed values, you should call SaveToDatabase
somewhere inside WCFService.SetValue()
and there's no need to expose SaveDatabase
as web service method.
Upvotes: 1